Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of commas in environment variable values #1077

Merged
merged 1 commit into from Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`")
na-- marked this conversation as resolved.
Show resolved Hide resolved
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