Skip to content

Commit

Permalink
check CanInterface before calling Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
danp authored and joeshaw committed Jan 29, 2018
1 parent ce5db18 commit a0ce5e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions envdecode.go
Expand Up @@ -118,6 +118,10 @@ func decode(target interface{}, strict bool) (int, error) {
fallthrough

case reflect.Struct:
if !f.Addr().CanInterface() {
continue
}

ss := f.Addr().Interface()
_, custom := ss.(Decoder)
if custom {
Expand Down
3 changes: 3 additions & 0 deletions envdecode_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"sort"
"strconv"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -59,6 +60,8 @@ type testConfig struct {
DefaultSliceInt []int `env:"TEST_UNSET,asdf=asdf,default=1;2;3"`
DefaultDuration time.Duration `env:"TEST_UNSET,asdf=asdf,default=24h"`
DefaultURL *url.URL `env:"TEST_UNSET,default=http://example.com"`

cantInterfaceField sync.Mutex
}

type testConfigNoSet struct {
Expand Down

0 comments on commit a0ce5e6

Please sign in to comment.