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>
This commit is contained in:
16
shell/ash_test/ash-quoting/dollar_altvalue1.right
Normal file
16
shell/ash_test/ash-quoting/dollar_altvalue1.right
Normal file
@@ -0,0 +1,16 @@
|
||||
Unquoted b c d
|
||||
|b|
|
||||
|c|
|
||||
|d|
|
||||
Unquoted 'b c' d
|
||||
|b c|
|
||||
|d|
|
||||
Unquoted "b c" d
|
||||
|b c|
|
||||
|d|
|
||||
Quoted b c d
|
||||
|b c d|
|
||||
Quoted 'b c' d
|
||||
|'b c' d|
|
||||
Quoted "b c" d
|
||||
|b c d|
|
16
shell/ash_test/ash-quoting/dollar_altvalue1.tests
Executable file
16
shell/ash_test/ash-quoting/dollar_altvalue1.tests
Executable file
@@ -0,0 +1,16 @@
|
||||
f() { for i; do echo "|$i|"; done; }
|
||||
x=a
|
||||
|
||||
echo Unquoted b c d
|
||||
f ${x:+b c d}
|
||||
echo Unquoted "'b c' d"
|
||||
f ${x:+'b c' d}
|
||||
echo Unquoted '"b c" d'
|
||||
f ${x:+"b c" d}
|
||||
|
||||
echo Quoted b c d
|
||||
f "${x:+b c d}"
|
||||
echo Quoted "'b c' d"
|
||||
f "${x:+'b c' d}"
|
||||
echo Quoted '"b c" d'
|
||||
f "${x:+"b c" d}"
|
14
shell/ash_test/ash-quoting/dollar_repl_bash1.right
Normal file
14
shell/ash_test/ash-quoting/dollar_repl_bash1.right
Normal file
@@ -0,0 +1,14 @@
|
||||
|y|
|
||||
|zx|
|
||||
|y|
|
||||
|zx|
|
||||
|y zx|
|
||||
|y zx|
|
||||
|y|
|
||||
|zy|
|
||||
|z|
|
||||
|y|
|
||||
|zy|
|
||||
|z|
|
||||
|y zy z|
|
||||
|y zy z|
|
12
shell/ash_test/ash-quoting/dollar_repl_bash1.tests
Executable file
12
shell/ash_test/ash-quoting/dollar_repl_bash1.tests
Executable file
@@ -0,0 +1,12 @@
|
||||
f() { for i; do echo "|$i|"; done; }
|
||||
v=xx
|
||||
|
||||
f ${v/'x'/"y z"}
|
||||
f ${v/"x"/'y z'}
|
||||
f "${v/'x'/"y z"}"
|
||||
f "${v/"x"/'y z'}"
|
||||
|
||||
f ${v//'x'/"y z"}
|
||||
f ${v//"x"/'y z'}
|
||||
f "${v//'x'/"y z"}"
|
||||
f "${v//"x"/'y z'}"
|
@@ -1,5 +1,9 @@
|
||||
z
|
||||
z
|
||||
z
|
||||
z
|
||||
y
|
||||
y
|
||||
y
|
||||
y
|
||||
Ok:0
|
||||
|
@@ -1,6 +1,10 @@
|
||||
x=yz
|
||||
echo ${x#'y'}
|
||||
echo "${x#'y'}"
|
||||
echo ${x#"y"}
|
||||
echo "${x#"y"}"
|
||||
echo ${x%'z'}
|
||||
echo "${x%'z'}"
|
||||
echo ${x%"z"}
|
||||
echo "${x%"z"}"
|
||||
echo Ok:$?
|
||||
|
@@ -1,3 +1,5 @@
|
||||
Nothing:
|
||||
Nothing:
|
||||
Nothing:
|
||||
Nothing:
|
||||
Ok:0
|
||||
|
@@ -1,4 +1,6 @@
|
||||
x='\\\\'
|
||||
printf Nothing:'%s\n' ${x#'\\\\'}
|
||||
printf Nothing:'%s\n' "${x#'\\\\'}"
|
||||
printf Nothing:'%s\n' ${x#"\\\\\\\\"}
|
||||
printf Nothing:'%s\n' "${x#"\\\\\\\\"}"
|
||||
echo Ok:$?
|
||||
|
@@ -229,8 +229,8 @@ do
|
||||
'') split "$d0$f1$d1$f2$d2$f3$d3" "[2]($f1)($f2)" "($f1)($f2)" ;;
|
||||
' ') ;;
|
||||
*) x=$f2$d2$f3$d3
|
||||
x=${x# } #was x=${x#' '} hush needs fixing for this to work
|
||||
x=${x% } #was x=${x%' '}
|
||||
x=${x#' '}
|
||||
x=${x%' '}
|
||||
split "$d0$f1$d1$f2$d2$f3$d3" "[3]($f1)($f2)($f3)" "($f1)($x)"
|
||||
;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user