Skip to content

Commit

Permalink
Fix handling of commas in environment variable values
Browse files Browse the repository at this point in the history
This should close #1006
  • Loading branch information
na-- committed Jul 10, 2019
1 parent 5af8e03 commit c854389
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/runtime_options.go
Expand Up @@ -52,7 +52,7 @@ func runtimeOptionFlagSet(includeSysEnv bool) *pflag.FlagSet {
flags := pflag.NewFlagSet("", 0)
flags.SortFlags = false
flags.Bool("include-system-env-vars", includeSysEnv, "pass the real system environment variables to the runtime")
flags.StringSliceP("env", "e", nil, "add/override environment variable with `VAR=value`")
flags.StringArrayP("env", "e", nil, "add/override environment variable with `VAR=value`")
return flags
}

Expand All @@ -68,7 +68,7 @@ func getRuntimeOptions(flags *pflag.FlagSet) (lib.RuntimeOptions, error) {
}

// Set/overwrite environment variables with custom user-supplied values
envVars, err := flags.GetStringSlice("env")
envVars, err := flags.GetStringArray("env")
if err != nil {
return opts, err
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/runtime_options_test.go
Expand Up @@ -178,6 +178,14 @@ var envVarTestCases = []EnvVarTest{
false,
map[string]string{"test1": "value 1", "test2": "value 2"},
},
{
"valid env vars with special chars",
true,
map[string]string{"test1": "value 1"},
[]string{"--env", "test2=value,2", "-e", `test3= , ,,, value, ,, 2!'@#,"`},
false,
map[string]string{"test1": "value 1", "test2": "value,2", "test3": ` , ,,, value, ,, 2!'@#,"`},
},
}

func TestEnvVars(t *testing.T) {
Expand All @@ -204,7 +212,7 @@ func TestEnvVars(t *testing.T) {
jsCode := "export default function() {\n"
for key, val := range tc.expEnv {
jsCode += fmt.Sprintf(
"if (__ENV.%s !== '%s') { throw new Error('Invalid %s: ' + __ENV.%s); }\n",
"if (__ENV.%s !== `%s`) { throw new Error('Invalid %s: ' + __ENV.%s); }\n",
key, val, key, key,
)
}
Expand Down

0 comments on commit c854389

Please sign in to comment.