diff --git a/tools/utils/shlex/shlex.go b/tools/utils/shlex/shlex.go index 5f6f4f9e0..839fa1397 100644 --- a/tools/utils/shlex/shlex.go +++ b/tools/utils/shlex/shlex.go @@ -210,7 +210,7 @@ func SplitForCompletion(s string) (argv []string, position_of_last_arg int) { } if pos < len(s) { // trailing whitespace argv = append(argv, "") - position_of_last_arg += len(s) - pos + 1 + position_of_last_arg = len(s) } } } else { diff --git a/tools/utils/shlex/shlex_test.go b/tools/utils/shlex/shlex_test.go index f6be690eb..1d55ac419 100644 --- a/tools/utils/shlex/shlex_test.go +++ b/tools/utils/shlex/shlex_test.go @@ -96,6 +96,9 @@ func TestSplitForCompletion(t *testing.T) { test("a b", 2, "a", "b") test("a b ", 4, "a", "b", "") test("a b ", 5, "a", "b", "") + test("ab cd ", 6, "ab", "cd", "") + test("launch --type ", 14, "launch", "--type", "") + test(`a "b c" `, 8, "a", "b c", "") test(`a "b c"`, 2, "a", "b c") test(`a "b c`, 2, "a", "b c") }