Skip to content

Commit

Permalink
fix: panic on private field pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmashko committed Sep 26, 2023
1 parent 8fa8e47 commit d8f6476
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions parser_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,13 @@ func TestParse_PrivateField_Ok(t *testing.T) {
t.Fatal(err)
}
}

func TestParse_PrivateFieldPointer_Ok(t *testing.T) {
cfg := struct {
field2 *string `default:"f2"`
}{}

if err := envconf.Parse(&cfg); err != nil {
t.Fatal(err)
}
}
3 changes: 3 additions & 0 deletions type_pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (f *ptrType) define() error {
}

if f.field.isSet() && f.tmp != nil {
if !f.tmp.CanSet() {
return nil
}
f.v.Set(*f.tmp)
}

Expand Down

0 comments on commit d8f6476

Please sign in to comment.