diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-17 14:21:38 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-17 14:21:38 +0200 |
commit | b762c784caa78877a9949224af425e52db237beb (patch) | |
tree | f452b87d4abd8d48bb1c711f9330c786b4c3fe6e /shell/ash_test | |
parent | 1fbb73fc4cee44f0768fbb09fe8f41a52d47ed3e (diff) | |
download | busybox-w32-b762c784caa78877a9949224af425e52db237beb.tar.gz busybox-w32-b762c784caa78877a9949224af425e52db237beb.tar.bz2 busybox-w32-b762c784caa78877a9949224af425e52db237beb.zip |
hush: improve ${var#...}, ${var:+...} and ${var/.../...} - handle quoting
dollar_altvalue1 test partially fails: word splitting of unquoted ${var:+...}
is not correct
function old new delta
encode_then_expand_vararg - 443 +443
expand_one_var 1599 1610 +11
parse_stream 2756 2753 -3
encode_string 250 242 -8
setup_heredoc 308 298 -10
expand_and_evaluate_arith 106 96 -10
encode_then_expand_string 142 126 -16
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/5 up/down: 454/-47) Total: 407 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test')
-rw-r--r-- | shell/ash_test/ash-quoting/dollar_altvalue1.right | 16 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/dollar_altvalue1.tests | 16 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/dollar_repl_bash1.right | 14 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/dollar_repl_bash1.tests | 12 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/squote_in_varexp.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/squote_in_varexp.tests | 4 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/squote_in_varexp2.right | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/squote_in_varexp2.tests | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-z_slow/many_ifs.tests | 4 |
9 files changed, 72 insertions, 2 deletions
diff --git a/shell/ash_test/ash-quoting/dollar_altvalue1.right b/shell/ash_test/ash-quoting/dollar_altvalue1.right new file mode 100644 index 000000000..5cd495d3b --- /dev/null +++ b/shell/ash_test/ash-quoting/dollar_altvalue1.right | |||
@@ -0,0 +1,16 @@ | |||
1 | Unquoted b c d | ||
2 | |b| | ||
3 | |c| | ||
4 | |d| | ||
5 | Unquoted 'b c' d | ||
6 | |b c| | ||
7 | |d| | ||
8 | Unquoted "b c" d | ||
9 | |b c| | ||
10 | |d| | ||
11 | Quoted b c d | ||
12 | |b c d| | ||
13 | Quoted 'b c' d | ||
14 | |'b c' d| | ||
15 | Quoted "b c" d | ||
16 | |b c d| | ||
diff --git a/shell/ash_test/ash-quoting/dollar_altvalue1.tests b/shell/ash_test/ash-quoting/dollar_altvalue1.tests new file mode 100755 index 000000000..f4dc8caec --- /dev/null +++ b/shell/ash_test/ash-quoting/dollar_altvalue1.tests | |||
@@ -0,0 +1,16 @@ | |||
1 | f() { for i; do echo "|$i|"; done; } | ||
2 | x=a | ||
3 | |||
4 | echo Unquoted b c d | ||
5 | f ${x:+b c d} | ||
6 | echo Unquoted "'b c' d" | ||
7 | f ${x:+'b c' d} | ||
8 | echo Unquoted '"b c" d' | ||
9 | f ${x:+"b c" d} | ||
10 | |||
11 | echo Quoted b c d | ||
12 | f "${x:+b c d}" | ||
13 | echo Quoted "'b c' d" | ||
14 | f "${x:+'b c' d}" | ||
15 | echo Quoted '"b c" d' | ||
16 | f "${x:+"b c" d}" | ||
diff --git a/shell/ash_test/ash-quoting/dollar_repl_bash1.right b/shell/ash_test/ash-quoting/dollar_repl_bash1.right new file mode 100644 index 000000000..f5e9309f4 --- /dev/null +++ b/shell/ash_test/ash-quoting/dollar_repl_bash1.right | |||
@@ -0,0 +1,14 @@ | |||
1 | |y| | ||
2 | |zx| | ||
3 | |y| | ||
4 | |zx| | ||
5 | |y zx| | ||
6 | |y zx| | ||
7 | |y| | ||
8 | |zy| | ||
9 | |z| | ||
10 | |y| | ||
11 | |zy| | ||
12 | |z| | ||
13 | |y zy z| | ||
14 | |y zy z| | ||
diff --git a/shell/ash_test/ash-quoting/dollar_repl_bash1.tests b/shell/ash_test/ash-quoting/dollar_repl_bash1.tests new file mode 100755 index 000000000..912635925 --- /dev/null +++ b/shell/ash_test/ash-quoting/dollar_repl_bash1.tests | |||
@@ -0,0 +1,12 @@ | |||
1 | f() { for i; do echo "|$i|"; done; } | ||
2 | v=xx | ||
3 | |||
4 | f ${v/'x'/"y z"} | ||
5 | f ${v/"x"/'y z'} | ||
6 | f "${v/'x'/"y z"}" | ||
7 | f "${v/"x"/'y z'}" | ||
8 | |||
9 | f ${v//'x'/"y z"} | ||
10 | f ${v//"x"/'y z'} | ||
11 | f "${v//'x'/"y z"}" | ||
12 | f "${v//"x"/'y z'}" | ||
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp.right b/shell/ash_test/ash-quoting/squote_in_varexp.right index a75c0bfd6..4a457021b 100644 --- a/shell/ash_test/ash-quoting/squote_in_varexp.right +++ b/shell/ash_test/ash-quoting/squote_in_varexp.right | |||
@@ -1,5 +1,9 @@ | |||
1 | z | 1 | z |
2 | z | 2 | z |
3 | z | ||
4 | z | ||
5 | y | ||
6 | y | ||
3 | y | 7 | y |
4 | y | 8 | y |
5 | Ok:0 | 9 | Ok:0 |
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp.tests b/shell/ash_test/ash-quoting/squote_in_varexp.tests index a2d05a246..4afc52107 100755 --- a/shell/ash_test/ash-quoting/squote_in_varexp.tests +++ b/shell/ash_test/ash-quoting/squote_in_varexp.tests | |||
@@ -1,6 +1,10 @@ | |||
1 | x=yz | 1 | x=yz |
2 | echo ${x#'y'} | 2 | echo ${x#'y'} |
3 | echo "${x#'y'}" | 3 | echo "${x#'y'}" |
4 | echo ${x#"y"} | ||
5 | echo "${x#"y"}" | ||
4 | echo ${x%'z'} | 6 | echo ${x%'z'} |
5 | echo "${x%'z'}" | 7 | echo "${x%'z'}" |
8 | echo ${x%"z"} | ||
9 | echo "${x%"z"}" | ||
6 | echo Ok:$? | 10 | echo Ok:$? |
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp2.right b/shell/ash_test/ash-quoting/squote_in_varexp2.right index 9d0add3c5..d03047024 100644 --- a/shell/ash_test/ash-quoting/squote_in_varexp2.right +++ b/shell/ash_test/ash-quoting/squote_in_varexp2.right | |||
@@ -1,3 +1,5 @@ | |||
1 | Nothing: | 1 | Nothing: |
2 | Nothing: | 2 | Nothing: |
3 | Nothing: | ||
4 | Nothing: | ||
3 | Ok:0 | 5 | Ok:0 |
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp2.tests b/shell/ash_test/ash-quoting/squote_in_varexp2.tests index 806ad12b9..2797725cc 100755 --- a/shell/ash_test/ash-quoting/squote_in_varexp2.tests +++ b/shell/ash_test/ash-quoting/squote_in_varexp2.tests | |||
@@ -1,4 +1,6 @@ | |||
1 | x='\\\\' | 1 | x='\\\\' |
2 | printf Nothing:'%s\n' ${x#'\\\\'} | 2 | printf Nothing:'%s\n' ${x#'\\\\'} |
3 | printf Nothing:'%s\n' "${x#'\\\\'}" | 3 | printf Nothing:'%s\n' "${x#'\\\\'}" |
4 | printf Nothing:'%s\n' ${x#"\\\\\\\\"} | ||
5 | printf Nothing:'%s\n' "${x#"\\\\\\\\"}" | ||
4 | echo Ok:$? | 6 | echo Ok:$? |
diff --git a/shell/ash_test/ash-z_slow/many_ifs.tests b/shell/ash_test/ash-z_slow/many_ifs.tests index 1f5b1b3a6..cf9a89874 100755 --- a/shell/ash_test/ash-z_slow/many_ifs.tests +++ b/shell/ash_test/ash-z_slow/many_ifs.tests | |||
@@ -229,8 +229,8 @@ do | |||
229 | '') split "$d0$f1$d1$f2$d2$f3$d3" "[2]($f1)($f2)" "($f1)($f2)" ;; | 229 | '') split "$d0$f1$d1$f2$d2$f3$d3" "[2]($f1)($f2)" "($f1)($f2)" ;; |
230 | ' ') ;; | 230 | ' ') ;; |
231 | *) x=$f2$d2$f3$d3 | 231 | *) x=$f2$d2$f3$d3 |
232 | x=${x# } #was x=${x#' '} hush needs fixing for this to work | 232 | x=${x#' '} |
233 | x=${x% } #was x=${x%' '} | 233 | x=${x%' '} |
234 | split "$d0$f1$d1$f2$d2$f3$d3" "[3]($f1)($f2)($f3)" "($f1)($x)" | 234 | split "$d0$f1$d1$f2$d2$f3$d3" "[3]($f1)($f2)($f3)" "($f1)($x)" |
235 | ;; | 235 | ;; |
236 | esac | 236 | esac |