Skip to content

Commit 0fbb566

Browse files
committed
fix(tar): avoid expansion on gtar options parse
Thanks-to: David Zaslavsky <[email protected]> Closes scop#152
1 parent 3e6ed1c commit 0fbb566

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

completions/tar

+16-15
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,22 @@ __gtar_parse_help_opt()
7979

8080
__gtar_parse_help_line()
8181
{
82-
local i
83-
84-
for i in $1; do
85-
case "$i" in
86-
# regular options
87-
--* | -*)
88-
__gtar_parse_help_opt "$i" "$2"
89-
;;
90-
91-
# end once there is single non-option word
92-
*)
93-
break
94-
;;
95-
esac
96-
done
82+
local -a tmp
83+
while read -ra tmp; do
84+
for i in "${tmp[@]}"; do
85+
case "$i" in
86+
# regular options
87+
--* | -*)
88+
__gtar_parse_help_opt "$i" "$2"
89+
;;
90+
91+
# end once there is single non-option word
92+
*)
93+
break
94+
;;
95+
esac
96+
done
97+
done <<<"$1"
9798
}
9899

99100
__gnu_tar_parse_help()

test/t/test_tar.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
from conftest import assert_bash_exec
66

77

8-
@pytest.mark.bashcomp(ignore_env=r"^-declare -f _tar$")
8+
@pytest.mark.bashcomp(ignore_env=r"^-declare -f _tar$||shopt -. failglob")
99
class TestTar:
1010
@pytest.fixture(scope="class")
1111
def gnu_tar(self, bash):
1212
got = assert_bash_exec(bash, "tar --version || :", want_output=True)
1313
if not re.search(r"\bGNU ", got):
1414
pytest.skip("Not GNU tar")
1515

16-
@pytest.mark.complete("tar ")
17-
def test_1(self, completion):
16+
@pytest.mark.complete("tar ", pre_cmds=("shopt -s failglob",))
17+
def test_1(self, bash, completion):
1818
assert completion
19+
assert_bash_exec(bash, "shopt -u failglob")
1920

2021
# Test "f" when mode is not as first option
2122
@pytest.mark.complete("tar zfc ", cwd="tar")

0 commit comments

Comments
 (0)