aboutsummaryrefslogtreecommitdiff
path: root/shell/hush_test
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-06 10:26:37 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-06 10:26:37 +0200
commitc49d2d97939d77be3d1f3bbbbf9db30a55771c15 (patch)
tree8cf0a9ad8fd7e0d9762684fef0a7a5a4f7d43859 /shell/hush_test
parentd383b49aefecea99e5bfb2f9eb2956f1c6c013e1 (diff)
downloadbusybox-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.right18
-rwxr-xr-xshell/hush_test/hush-glob/glob2.tests27
-rw-r--r--shell/hush_test/hush-vars/var_bash4.right25
-rwxr-xr-xshell/hush_test/hush-vars/var_bash4.tests52
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 @@
1Expected Actual
2Z\* : Z\*
3Z* : Z*
4Z\f : Z\f
5Z\* : Z\*
6
7Z\z : Z\z
8Zz : Zz
9Z\z : Z\z
10Z\z : Z\z
11
12Z\ : Z\
13Z\ : Z\
14
15Z\f Zf : Z\f Zf
16Z\f Zf : Z\f Zf
17
18Done: 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'
9v='\*'; echo 'Z\* :' Z$v
10 echo 'Z* :' Z\*
11 echo 'Z\f :' Z\\*
12 echo 'Z\* :' Z\\\* # NB! only this matches Z$v output
13echo
14v='\z'; echo 'Z\z :' Z$v
15 echo 'Zz :' Z\z
16 echo 'Z\z :' Z\\z
17 echo 'Z\z :' Z\\\z
18echo
19v='\'; echo 'Z\ :' Z$v
20 echo 'Z\ :' Z\\
21echo
22v='*'; echo 'Z\f Zf :' Z$v
23 echo 'Z\f Zf :' Z*
24echo
25
26rm 'Z\f' 'Zf'
27echo 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 @@
1Source: a*b\*c 1Source: a*b\*c
2Replace str: _\\_\z_ 2Replace str: _\\_\z_
3Pattern: single backslash and star: "replace literal star" 3Pattern: single backslash and star: "replace literal star"
4In assignment: a_\_z_b\*c
5Unquoted: a_\_z_b\*c 4Unquoted: a_\_z_b\*c
5Unquoted =: a_\_z_b\*c
6Quoted: a_\_\z_b\*c 6Quoted: a_\_\z_b\*c
7Quoted =: a_\_\z_b\*c
7Pattern: double backslash and star: "replace backslash and everything after it" 8Pattern: double backslash and star: "replace backslash and everything after it"
8In assignment: a*b_\_z_
9Unquoted: a*b_\_z_ 9Unquoted: a*b_\_z_
10Unquoted =: a*b_\_z_
10Quoted: a*b_\_\z_ 11Quoted: a*b_\_\z_
12Quoted =: a*b_\_\z_
11 13
12Source: a\bc 14Source: a\bc
13Replace str: _\\_\z_ 15Replace str: _\\_\z_
14Pattern: single backslash and b: "replace b" 16Pattern: single backslash and b: "replace b"
15In assignment: a\_\_z_c
16Unquoted: a\_\_z_c 17Unquoted: a\_\_z_c
18Unquoted =: a\_\_z_c
17Quoted: a\_\_\z_c 19Quoted: a\_\_\z_c
20Quoted =: a\_\_\z_c
18Pattern: double backslash and b: "replace backslash and b" 21Pattern: double backslash and b: "replace backslash and b"
19In assignment: a_\_z_c
20Unquoted: a_\_z_c 22Unquoted: a_\_z_c
23Unquoted =: a_\_z_c
21Quoted: a_\_\z_c 24Quoted: a_\_\z_c
25Quoted =: a_\_\z_c
26
27Source: a\bc
28Replace str: _\\_\z_ (as variable $s)
29Pattern: single backslash and b: "replace b"
30Unquoted: a\_\\_\z_c
31Unquoted =: a\_\\_\z_c
32Quoted: a\_\\_\z_c
33Quoted =: a\_\\_\z_c
34Pattern: double backslash and b: "replace backslash and b"
35Unquoted: a_\\_\z_c
36Unquoted =: a_\\_\z_c
37Quoted: a_\\_\z_c
38Quoted =: a_\\_\z_c
22 39
23Done: 0 40Done: 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
11v='a*b\*c' 14v='a*b\*c'
12echo 'Source: ' "$v" 15echo 'Source: ' "$v"
13echo 'Replace str: ' '_\\_\z_' 16echo 'Replace str: ' '_\\_\z_'
14 17
15echo 'Pattern: ' 'single backslash and star: "replace literal star"' 18echo 'Pattern: ' 'single backslash and star: "replace literal star"'
16r=${v/\*/_\\_\z_}
17echo 'In assignment:' "$r"
18echo 'Unquoted: ' ${v/\*/_\\_\z_} 19echo 'Unquoted: ' ${v/\*/_\\_\z_}
20r=${v/\*/_\\_\z_}
21echo 'Unquoted =: ' "$r"
19echo 'Quoted: ' "${v/\*/_\\_\z_}" 22echo 'Quoted: ' "${v/\*/_\\_\z_}"
23r="${v/\*/_\\_\z_}"
24echo 'Quoted =: ' "$r"
20 25
21echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"' 26echo 'Pattern: ' 'double backslash and star: "replace backslash and everything after it"'
22r=${v/\\*/_\\_\z_}
23echo 'In assignment:' "$r"
24echo 'Unquoted: ' ${v/\\*/_\\_\z_} 27echo 'Unquoted: ' ${v/\\*/_\\_\z_}
28r=${v/\\*/_\\_\z_}
29echo 'Unquoted =: ' "$r"
25echo 'Quoted: ' "${v/\\*/_\\_\z_}" 30echo 'Quoted: ' "${v/\\*/_\\_\z_}"
31r="${v/\\*/_\\_\z_}"
32echo 'Quoted =: ' "$r"
26 33
27echo 34echo
28 35
@@ -31,16 +38,43 @@ echo 'Source: ' "$v"
31echo 'Replace str: ' '_\\_\z_' 38echo 'Replace str: ' '_\\_\z_'
32 39
33echo 'Pattern: ' 'single backslash and b: "replace b"' 40echo 'Pattern: ' 'single backslash and b: "replace b"'
34r=${v/\b/_\\_\z_}
35echo 'In assignment:' "$r"
36echo 'Unquoted: ' ${v/\b/_\\_\z_} 41echo 'Unquoted: ' ${v/\b/_\\_\z_}
42r=${v/\b/_\\_\z_}
43echo 'Unquoted =: ' "$r"
37echo 'Quoted: ' "${v/\b/_\\_\z_}" 44echo 'Quoted: ' "${v/\b/_\\_\z_}"
45r="${v/\b/_\\_\z_}"
46echo 'Quoted =: ' "$r"
38 47
39echo 'Pattern: ' 'double backslash and b: "replace backslash and b"' 48echo 'Pattern: ' 'double backslash and b: "replace backslash and b"'
40r=${v/\\b/_\\_\z_}
41echo 'In assignment:' "$r"
42echo 'Unquoted: ' ${v/\\b/_\\_\z_} 49echo 'Unquoted: ' ${v/\\b/_\\_\z_}
50r=${v/\\b/_\\_\z_}
51echo 'Unquoted =: ' "$r"
43echo 'Quoted: ' "${v/\\b/_\\_\z_}" 52echo 'Quoted: ' "${v/\\b/_\\_\z_}"
53r="${v/\\b/_\\_\z_}"
54echo 'Quoted =: ' "$r"
55
56echo
57
58v='a\bc'
59s='_\\_\z_'
60echo 'Source: ' "$v"
61echo 'Replace str: ' "$s" '(as variable $s)'
62
63echo 'Pattern: ' 'single backslash and b: "replace b"'
64echo 'Unquoted: ' ${v/\b/$s}
65r=${v/\b/$s}
66echo 'Unquoted =: ' "$r"
67echo 'Quoted: ' "${v/\b/$s}"
68r="${v/\b/$s}"
69echo 'Quoted =: ' "$r"
70
71echo 'Pattern: ' 'double backslash and b: "replace backslash and b"'
72echo 'Unquoted: ' ${v/\\b/$s}
73r=${v/\\b/$s}
74echo 'Unquoted =: ' "$r"
75echo 'Quoted: ' "${v/\\b/$s}"
76r="${v/\\b/$s}"
77echo 'Quoted =: ' "$r"
44 78
45echo 79echo
46 80