diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-06 10:26:37 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-06 10:26:37 +0200 |
commit | c49d2d97939d77be3d1f3bbbbf9db30a55771c15 (patch) | |
tree | 8cf0a9ad8fd7e0d9762684fef0a7a5a4f7d43859 /shell/hush_test | |
parent | d383b49aefecea99e5bfb2f9eb2956f1c6c013e1 (diff) | |
download | busybox-w32-c49d2d97939d77be3d1f3bbbbf9db30a55771c15.tar.gz busybox-w32-c49d2d97939d77be3d1f3bbbbf9db30a55771c15.tar.bz2 busybox-w32-c49d2d97939d77be3d1f3bbbbf9db30a55771c15.zip |
hush: fix globbing+backslashes in unquoted $var expansion
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell/hush_test')
-rw-r--r-- | shell/hush_test/hush-glob/glob2.right | 18 | ||||
-rwxr-xr-x | shell/hush_test/hush-glob/glob2.tests | 27 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/var_bash4.right | 25 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/var_bash4.tests | 52 |
4 files changed, 109 insertions, 13 deletions
diff --git a/shell/hush_test/hush-glob/glob2.right b/shell/hush_test/hush-glob/glob2.right new file mode 100644 index 000000000..7a70c2263 --- /dev/null +++ b/shell/hush_test/hush-glob/glob2.right | |||
@@ -0,0 +1,18 @@ | |||
1 | Expected Actual | ||
2 | Z\* : Z\* | ||
3 | Z* : Z* | ||
4 | Z\f : Z\f | ||
5 | Z\* : Z\* | ||
6 | |||
7 | Z\z : Z\z | ||
8 | Zz : Zz | ||
9 | Z\z : Z\z | ||
10 | Z\z : Z\z | ||
11 | |||
12 | Z\ : Z\ | ||
13 | Z\ : Z\ | ||
14 | |||
15 | Z\f Zf : Z\f Zf | ||
16 | Z\f Zf : Z\f Zf | ||
17 | |||
18 | Done: 0 | ||
diff --git a/shell/hush_test/hush-glob/glob2.tests b/shell/hush_test/hush-glob/glob2.tests new file mode 100755 index 000000000..4dbc92599 --- /dev/null +++ b/shell/hush_test/hush-glob/glob2.tests | |||
@@ -0,0 +1,27 @@ | |||
1 | # This test demonstrates that in unquoted $v, backslashes expand by this rule: | ||
2 | # \z -> \\\z; \<eol> -> \\<eol> (for any z, special or not), | ||
3 | # and subsequently globbing converts \\ to \ and treats \z as literal z | ||
4 | # even if it is a special char. | ||
5 | |||
6 | >'Zf' | ||
7 | >'Z\f' | ||
8 | echo 'Expected' 'Actual' | ||
9 | v='\*'; echo 'Z\* :' Z$v | ||
10 | echo 'Z* :' Z\* | ||
11 | echo 'Z\f :' Z\\* | ||
12 | echo 'Z\* :' Z\\\* # NB! only this matches Z$v output | ||
13 | echo | ||
14 | v='\z'; echo 'Z\z :' Z$v | ||
15 | echo 'Zz :' Z\z | ||
16 | echo 'Z\z :' Z\\z | ||
17 | echo 'Z\z :' Z\\\z | ||
18 | echo | ||
19 | v='\'; echo 'Z\ :' Z$v | ||
20 | echo 'Z\ :' Z\\ | ||
21 | echo | ||
22 | v='*'; echo 'Z\f Zf :' Z$v | ||
23 | echo 'Z\f Zf :' Z* | ||
24 | echo | ||
25 | |||
26 | rm 'Z\f' 'Zf' | ||
27 | echo Done: $? | ||
diff --git a/shell/hush_test/hush-vars/var_bash4.right b/shell/hush_test/hush-vars/var_bash4.right index 600e8532f..0ef1bf661 100644 --- a/shell/hush_test/hush-vars/var_bash4.right +++ b/shell/hush_test/hush-vars/var_bash4.right | |||
@@ -1,23 +1,40 @@ | |||
1 | Source: a*b\*c | 1 | Source: a*b\*c |
2 | Replace str: _\\_\z_ | 2 | Replace str: _\\_\z_ |
3 | Pattern: single backslash and star: "replace literal star" | 3 | Pattern: single backslash and star: "replace literal star" |
4 | In assignment: a_\_z_b\*c | ||
5 | Unquoted: a_\_z_b\*c | 4 | Unquoted: a_\_z_b\*c |
5 | Unquoted =: a_\_z_b\*c | ||
6 | Quoted: a_\_\z_b\*c | 6 | Quoted: a_\_\z_b\*c |
7 | Quoted =: a_\_\z_b\*c | ||
7 | Pattern: double backslash and star: "replace backslash and everything after it" | 8 | Pattern: double backslash and star: "replace backslash and everything after it" |
8 | In assignment: a*b_\_z_ | ||
9 | Unquoted: a*b_\_z_ | 9 | Unquoted: a*b_\_z_ |
10 | Unquoted =: a*b_\_z_ | ||
10 | Quoted: a*b_\_\z_ | 11 | Quoted: a*b_\_\z_ |
12 | Quoted =: a*b_\_\z_ | ||
11 | 13 | ||
12 | Source: a\bc | 14 | Source: a\bc |
13 | Replace str: _\\_\z_ | 15 | Replace str: _\\_\z_ |
14 | Pattern: single backslash and b: "replace b" | 16 | Pattern: single backslash and b: "replace b" |
15 | In assignment: a\_\_z_c | ||
16 | Unquoted: a\_\_z_c | 17 | Unquoted: a\_\_z_c |
18 | Unquoted =: a\_\_z_c | ||
17 | Quoted: a\_\_\z_c | 19 | Quoted: a\_\_\z_c |
20 | Quoted =: a\_\_\z_c | ||
18 | Pattern: double backslash and b: "replace backslash and b" | 21 | Pattern: double backslash and b: "replace backslash and b" |
19 | In assignment: a_\_z_c | ||
20 | Unquoted: a_\_z_c | 22 | Unquoted: a_\_z_c |
23 | Unquoted =: a_\_z_c | ||
21 | Quoted: a_\_\z_c | 24 | Quoted: a_\_\z_c |
25 | Quoted =: a_\_\z_c | ||
26 | |||
27 | Source: a\bc | ||
28 | Replace str: _\\_\z_ (as variable $s) | ||
29 | Pattern: single backslash and b: "replace b" | ||
30 | Unquoted: a\_\\_\z_c | ||
31 | Unquoted =: a\_\\_\z_c | ||
32 | Quoted: a\_\\_\z_c | ||
33 | Quoted =: a\_\\_\z_c | ||
34 | Pattern: double backslash and b: "replace backslash and b" | ||
35 | Unquoted: a_\\_\z_c | ||
36 | Unquoted =: a_\\_\z_c | ||
37 | Quoted: a_\\_\z_c | ||
38 | Quoted =: a_\\_\z_c | ||
22 | 39 | ||
23 | Done: 0 | 40 | Done: 0 |
diff --git a/shell/hush_test/hush-vars/var_bash4.tests b/shell/hush_test/hush-vars/var_bash4.tests index d5470614b..32aa2b34c 100755 --- a/shell/hush_test/hush-vars/var_bash4.tests +++ b/shell/hush_test/hush-vars/var_bash4.tests | |||
@@ -6,23 +6,30 @@ | |||
6 | # even in quotes. | 6 | # even in quotes. |
7 | # | 7 | # |
8 | # bash4 (and probably bash3 too): "Quoted:" results are different from | 8 | # bash4 (and probably bash3 too): "Quoted:" results are different from |
9 | # unquoted and assignment expansions - they have a backslash before z. | 9 | # unquoted expansions - they have a backslash before z. |
10 | # | ||
11 | # The difference only exists if repl is a literal. If it is a variable: | ||
12 | # ${v/.../$s}, then all backslashes are preserved in both cases. | ||
10 | 13 | ||
11 | v='a*b\*c' | 14 | v='a*b\*c' |
12 | echo 'Source: ' "$v" | 15 | echo 'Source: ' "$v" |
13 | echo 'Replace str: ' '_\\_\z_' | 16 | echo 'Replace str: ' '_\\_\z_' |
14 | 17 | ||
15 | echo 'Pattern: ' 'single backslash and star: "replace literal star"' | 18 | echo 'Pattern: ' 'single backslash and star: "replace literal star"' |
16 | r=${v/\*/_\\_\z_} | ||
17 | echo 'In assignment:' "$r" | ||
18 | echo 'Unquoted: ' ${v/\*/_\\_\z_} | 19 | echo 'Unquoted: ' ${v/\*/_\\_\z_} |
20 | r=${v/\*/_\\_\z_} | ||
21 | echo 'Unquoted =: ' "$r" | ||
19 | echo 'Quoted: ' "${v/\*/_\\_\z_}" | 22 | echo 'Quoted: ' "${v/\*/_\\_\z_}" |
23 | r="${v/\*/_\\_\z_}" | ||
24 | echo 'Quoted =: ' "$r" | ||
20 | 25 | ||
21 | echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"' | 26 | echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"' |
22 | r=${v/\\*/_\\_\z_} | ||
23 | echo 'In assignment:' "$r" | ||
24 | echo 'Unquoted: ' ${v/\\*/_\\_\z_} | 27 | echo 'Unquoted: ' ${v/\\*/_\\_\z_} |
28 | r=${v/\\*/_\\_\z_} | ||
29 | echo 'Unquoted =: ' "$r" | ||
25 | echo 'Quoted: ' "${v/\\*/_\\_\z_}" | 30 | echo 'Quoted: ' "${v/\\*/_\\_\z_}" |
31 | r="${v/\\*/_\\_\z_}" | ||
32 | echo 'Quoted =: ' "$r" | ||
26 | 33 | ||
27 | echo | 34 | echo |
28 | 35 | ||
@@ -31,16 +38,43 @@ echo 'Source: ' "$v" | |||
31 | echo 'Replace str: ' '_\\_\z_' | 38 | echo 'Replace str: ' '_\\_\z_' |
32 | 39 | ||
33 | echo 'Pattern: ' 'single backslash and b: "replace b"' | 40 | echo 'Pattern: ' 'single backslash and b: "replace b"' |
34 | r=${v/\b/_\\_\z_} | ||
35 | echo 'In assignment:' "$r" | ||
36 | echo 'Unquoted: ' ${v/\b/_\\_\z_} | 41 | echo 'Unquoted: ' ${v/\b/_\\_\z_} |
42 | r=${v/\b/_\\_\z_} | ||
43 | echo 'Unquoted =: ' "$r" | ||
37 | echo 'Quoted: ' "${v/\b/_\\_\z_}" | 44 | echo 'Quoted: ' "${v/\b/_\\_\z_}" |
45 | r="${v/\b/_\\_\z_}" | ||
46 | echo 'Quoted =: ' "$r" | ||
38 | 47 | ||
39 | echo 'Pattern: ' 'double backslash and b: "replace backslash and b"' | 48 | echo 'Pattern: ' 'double backslash and b: "replace backslash and b"' |
40 | r=${v/\\b/_\\_\z_} | ||
41 | echo 'In assignment:' "$r" | ||
42 | echo 'Unquoted: ' ${v/\\b/_\\_\z_} | 49 | echo 'Unquoted: ' ${v/\\b/_\\_\z_} |
50 | r=${v/\\b/_\\_\z_} | ||
51 | echo 'Unquoted =: ' "$r" | ||
43 | echo 'Quoted: ' "${v/\\b/_\\_\z_}" | 52 | echo 'Quoted: ' "${v/\\b/_\\_\z_}" |
53 | r="${v/\\b/_\\_\z_}" | ||
54 | echo 'Quoted =: ' "$r" | ||
55 | |||
56 | echo | ||
57 | |||
58 | v='a\bc' | ||
59 | s='_\\_\z_' | ||
60 | echo 'Source: ' "$v" | ||
61 | echo 'Replace str: ' "$s" '(as variable $s)' | ||
62 | |||
63 | echo 'Pattern: ' 'single backslash and b: "replace b"' | ||
64 | echo 'Unquoted: ' ${v/\b/$s} | ||
65 | r=${v/\b/$s} | ||
66 | echo 'Unquoted =: ' "$r" | ||
67 | echo 'Quoted: ' "${v/\b/$s}" | ||
68 | r="${v/\b/$s}" | ||
69 | echo 'Quoted =: ' "$r" | ||
70 | |||
71 | echo 'Pattern: ' 'double backslash and b: "replace backslash and b"' | ||
72 | echo 'Unquoted: ' ${v/\\b/$s} | ||
73 | r=${v/\\b/$s} | ||
74 | echo 'Unquoted =: ' "$r" | ||
75 | echo 'Quoted: ' "${v/\\b/$s}" | ||
76 | r="${v/\\b/$s}" | ||
77 | echo 'Quoted =: ' "$r" | ||
44 | 78 | ||
45 | echo | 79 | echo |
46 | 80 | ||