From 8148fdb18dbcf22a9c9c724fc9b22b8adb5ee7dd Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 11 Aug 2021 13:26:17 +0700 Subject: os/exec: check for escaped backslash when ParseCommandArgs Given the following string "cmd /a\ b" to ParseCommandArgs now it should return "cmd" and ["/a b"] not ["/a\", "b"], because the space after a is escaped using backslash. --- lib/os/exec/exec_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/os/exec/exec_test.go') diff --git a/lib/os/exec/exec_test.go b/lib/os/exec/exec_test.go index 90771dbb..38e089d0 100644 --- a/lib/os/exec/exec_test.go +++ b/lib/os/exec/exec_test.go @@ -41,6 +41,18 @@ func TestParseCommandArg(t *testing.T) { in: "a `b'c`", expCmd: `a`, expArgs: []string{`b'c`}, + }, { + in: `a\ b c\ d`, + expCmd: "a b", + expArgs: []string{"c d"}, + }, { + in: `a\\ b c\\ d`, + expCmd: `a\`, + expArgs: []string{"b", `c\`, "d"}, + }, { + in: `a\\\ b c\\\ d`, + expCmd: `a\ b`, + expArgs: []string{`c\ d`}, }} for _, c := range cases { -- cgit v1.3-6-g1900