diff --git a/exports.go b/exports.go index ea32407..9e5cf80 100644 --- a/exports.go +++ b/exports.go @@ -11,7 +11,7 @@ func DumpExportsFile(exportsData, envDir string) error { for _, line := range lines { if found, key, value := ParseExportsFileLine(line); found { - err := WriteEnvFile(envDir, key, value[1 : len(value)-1]) + err := WriteEnvFile(envDir, key, value) if err != nil { return err } @@ -24,7 +24,11 @@ func ParseExportsFileLine(line string) (bool, string, string) { components := strings.Split(line, "=") export := strings.Split(components[0], " ") if strings.TrimSpace(export[0]) == "export" { - return true, strings.TrimSpace(export[1]), components[1] + val := strings.TrimSpace(components[1]) + if string(val[0]) == "\"" && string(val[len(val)-1]) == "\"" { + val = val[1: len(val)-1] + } + return true, strings.TrimSpace(export[1]), val } else { return false, "", "" } diff --git a/exports_test.go b/exports_test.go index 8c40000..cfb1baa 100644 --- a/exports_test.go +++ b/exports_test.go @@ -51,6 +51,52 @@ export FOO=bar t.Error(err.Error()) } + if strings.TrimSpace(string(actual)) != expected { + t.Errorf("Expected %s; got %s", expected, actual) + } +} + +func TestDumpExportsFileWithQuotes(t *testing.T) { + envDir, err := ioutil.TempDir("", "env") + + exports := ` +export FOO="bar" +` + err = cnbshim.DumpExportsFile(exports, envDir) + if err != nil { + t.Error(err.Error()) + } + + expectedFile := filepath.Join(envDir, "FOO") + expected := "bar" + actual, err := ioutil.ReadFile(expectedFile) + if err != nil { + t.Error(err.Error()) + } + + if strings.TrimSpace(string(actual)) != expected { + t.Errorf("Expected %s; got %s", expected, actual) + } +} + +func TestDumpExportsFileWithEscapedQuotes(t *testing.T) { + envDir, err := ioutil.TempDir("", "env") + + exports := ` +export FOO="b\"a\"r" +` + err = cnbshim.DumpExportsFile(exports, envDir) + if err != nil { + t.Error(err.Error()) + } + + expectedFile := filepath.Join(envDir, "FOO") + expected := "b\\\"a\\\"r" + actual, err := ioutil.ReadFile(expectedFile) + if err != nil { + t.Error(err.Error()) + } + if strings.TrimSpace(string(actual)) != expected { t.Errorf("Expected %s; got %s", expected, actual) }