Backslash in Windows paths break env variables
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 378
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 74
Description
Windows has env paths that can end with a backslash: `BASE_DIR=C:\Program Files (x86)\CODE\`.
This causes issues when running through the agent when it attempts to parse the newline characters and slashes.
```diff
diff --git a/env/export_test.go b/env/export_test.go
index 89434a96..56fb2a37 100644
--- a/env/export_test.go
+++ b/env/export_test.go
@@ -23,6 +23,7 @@ func TestFromExportHandlesNewlines(t *testing.T) {
`another space "`,
`declare -x VAR6="ends with a quote \"`,
`and a new line \""`,
+ `declare -x VAR7="ends with a slash\"`,
`declare -x _="/usr/local/bin/watch"`,
}
@@ -36,6 +37,7 @@ func TestFromExportHandlesNewlines(t *testing.T) {
assertEqualEnv(t, `VAR4`, `ends with a space `, env)
assertEqualEnv(t, `VAR5`, "ends with\nanother space ", env)
assertEqualEnv(t, `VAR6`, "ends with a quote \"\nand a new line \"", env)
+ assertEqualEnv(t, `VAR7`, `ends with a slash\`, env)
assertEqualEnv(t, `_`, `/usr/local/bin/watch`, env)
}
```
Fails with:
```
--- FAIL: TestFromExportHandlesNewlines (0.00s)
export_test.go:40:
Error Trace: export_test.go:203
export_test.go:40
Error: Not equal:
expected: "ends with a slash\\"
actual : "ends with a slash\"\ndeclare -x _=\"/usr/local/bin/watch"
Diff:
--- Expected
+++ Actual
@@ -1 +1,2 @@
-ends with a slash\
+ends with a slash"
+declare -x _="/usr/local/bin/watch
Test: TestFromExportHandlesNewlines
FAIL
exit status 1
FAIL github.com/buildkite/agent/v3/env 0.421s
```
As it merges the `\` into the next line.
OS: Windows 10
Agent: v3.22.1
Contributor guide
Assessment
This issue has not been assessed yet.