Commit be268a04 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #1587 from joshfng/master

provisioner/shell: single quote env var values.
parents 2fd3f64a 5835ca42
...@@ -170,11 +170,14 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { ...@@ -170,11 +170,14 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
} }
// Do a check for bad environment variables, such as '=foo', 'foobar' // Do a check for bad environment variables, such as '=foo', 'foobar'
for _, kv := range p.config.Vars { for idx, kv := range p.config.Vars {
vs := strings.SplitN(kv, "=", 2) vs := strings.SplitN(kv, "=", 2)
if len(vs) != 2 || vs[0] == "" { if len(vs) != 2 || vs[0] == "" {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Environment variable not in format 'key=value': %s", kv)) fmt.Errorf("Environment variable not in format 'key=value': %s", kv))
} else {
// Single quote env var values
p.config.Vars[idx] = fmt.Sprintf("%s='%s'", vs[0], vs[1])
} }
} }
......
...@@ -199,3 +199,21 @@ func TestProvisionerPrepare_EnvironmentVars(t *testing.T) { ...@@ -199,3 +199,21 @@ func TestProvisionerPrepare_EnvironmentVars(t *testing.T) {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
} }
func TestProvisionerQuote_EnvironmentVars(t *testing.T) {
config := testConfig()
config["environment_vars"] = []string{"keyone=valueone", "keytwo=value\ntwo"}
p := new(Provisioner)
p.Prepare(config)
expectedValue := "keyone='valueone'"
if p.config.Vars[0] != expectedValue {
t.Fatalf("%s should be equal to %s", p.config.Vars[0], expectedValue)
}
expectedValue = "keytwo='value\ntwo'"
if p.config.Vars[1] != expectedValue {
t.Fatalf("%s should be equal to %s", p.config.Vars[1], expectedValue)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment