Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc9efc2

Browse files
authored
fix: Allow setting STUN to an empty string (#1502)
This allows users to entirely disable STUN.
1 parent 668a671 commit fc9efc2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cli/cliflag/cliflag.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func StringVarP(flagset *pflag.FlagSet, p *string, name string, shorthand string
4040
func StringArrayVarP(flagset *pflag.FlagSet, ptr *[]string, name string, shorthand string, env string, def []string, usage string) {
4141
val, ok := os.LookupEnv(env)
4242
if ok {
43-
def = strings.Split(val, ",")
43+
if val == "" {
44+
def = []string{}
45+
} else {
46+
def = strings.Split(val, ",")
47+
}
4448
}
4549
flagset.StringArrayVarP(ptr, name, shorthand, def, usage)
4650
}

cli/cliflag/cliflag_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ func TestCliflag(t *testing.T) {
9696
require.Equal(t, []string{"wow", "test"}, got)
9797
})
9898

99+
t.Run("StringArrayEnvVarEmpty", func(t *testing.T) {
100+
var ptr []string
101+
flagset, name, shorthand, env, usage := randomFlag()
102+
t.Setenv(env, "")
103+
cliflag.StringArrayVarP(flagset, &ptr, name, shorthand, env, nil, usage)
104+
got, err := flagset.GetStringArray(name)
105+
require.NoError(t, err)
106+
require.Equal(t, []string{}, got)
107+
})
108+
99109
t.Run("IntDefault", func(t *testing.T) {
100110
var ptr uint8
101111
flagset, name, shorthand, env, usage := randomFlag()

0 commit comments

Comments
 (0)