fix: Don't double backslashes in shellQuote
This commit is contained in:
1 parent
740f357900
commit
57b732b602
2 files changed
+5
-9
No files matched your search
@@ -24,18 +24,12 @@ func shellQuote(s string) string {
|
|||||||
inSingleQuotes := false
|
inSingleQuotes := false
|
||||||
for _, b := range []byte(s) {
|
for _, b := range []byte(s) {
|
||||||
switch b {
|
switch b {
|
||||||
case backslash:
|
|
||||||
if !inSingleQuotes {
|
|
||||||
result = append(result, singleQuote)
|
|
||||||
inSingleQuotes = true
|
|
||||||
}
|
|
||||||
result = append(result, backslash, backslash)
|
|
||||||
case singleQuote:
|
case singleQuote:
|
||||||
if inSingleQuotes {
|
if inSingleQuotes {
|
||||||
result = append(result, singleQuote)
|
result = append(result, singleQuote)
|
||||||
inSingleQuotes = false
|
inSingleQuotes = false
|
||||||
}
|
}
|
||||||
result = append(result, '\\', singleQuote)
|
result = append(result, backslash, singleQuote)
|
||||||
default:
|
default:
|
||||||
if !inSingleQuotes {
|
if !inSingleQuotes {
|
||||||
result = append(result, singleQuote)
|
result = append(result, singleQuote)
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ func TestShellQuote(t *testing.T) {
|
|||||||
`'`: `\'`,
|
`'`: `\'`,
|
||||||
`''`: `\'\'`,
|
`''`: `\'\'`,
|
||||||
`'a'`: `\''a'\'`,
|
`'a'`: `\''a'\'`,
|
||||||
`\`: `'\\'`,
|
`\`: `'\'`,
|
||||||
`\a`: `'\\a'`,
|
`\'`: `'\'\'`,
|
||||||
|
`\a`: `'\a'`,
|
||||||
|
`\n`: `'\n'`,
|
||||||
`$a`: `'$a'`,
|
`$a`: `'$a'`,
|
||||||
`a`: `a`,
|
`a`: `a`,
|
||||||
`a/b`: `a/b`,
|
`a/b`: `a/b`,
|
||||||
|
|||||||
Reference in new issue
Block a user