diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-29 16:59:06 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-29 16:59:06 +0200 |
commit | 8286513838beaf9ccaab15bb5905248c3b7b8a69 (patch) | |
tree | b7d72f0867668509260ea6b074c416702fb6fa2b | |
parent | 3b4d04b77eb5cfdb8ac6a799a3f3ccf1e455d0e7 (diff) | |
download | busybox-w32-8286513838beaf9ccaab15bb5905248c3b7b8a69.tar.gz busybox-w32-8286513838beaf9ccaab15bb5905248c3b7b8a69.tar.bz2 busybox-w32-8286513838beaf9ccaab15bb5905248c3b7b8a69.zip |
hush: rework input char buffering to allow more than one-deep peek
This fixes backslash+newline continuation in
$VAR\
NAME
construct. (ash has a bug there as well).
function old new delta
file_peek2 - 74 +74
parse_dollar 746 773 +27
expand_vars_to_list 1143 1167 +24
setup_string_in_str 32 46 +14
setup_file_in_str 33 47 +14
file_get 264 278 +14
static_peek2 - 7 +7
file_peek 91 72 -19
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 174/-19) Total: 155 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash_test/ash-vars/var_serial.right | 5 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_serial.tests | 22 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_subst_in_for.right | 40 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_subst_in_for.tests | 40 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_unbackslash.right | 11 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_unbackslash.tests | 23 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_unbackslash1.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_unbackslash1.tests | 15 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/var_unbackslash1.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/var_unbackslash1.tests | 15 |
10 files changed, 177 insertions, 0 deletions
diff --git a/shell/ash_test/ash-vars/var_serial.right b/shell/ash_test/ash-vars/var_serial.right new file mode 100644 index 000000000..42aa33057 --- /dev/null +++ b/shell/ash_test/ash-vars/var_serial.right | |||
@@ -0,0 +1,5 @@ | |||
1 | Assignments only: c=a | ||
2 | Assignments and a command: c=a | ||
3 | Assignments and a builtin: c=a | ||
4 | Assignments and a function: c=a | ||
5 | Done | ||
diff --git a/shell/ash_test/ash-vars/var_serial.tests b/shell/ash_test/ash-vars/var_serial.tests new file mode 100755 index 000000000..6b4a4cdf7 --- /dev/null +++ b/shell/ash_test/ash-vars/var_serial.tests | |||
@@ -0,0 +1,22 @@ | |||
1 | a=a | ||
2 | |||
3 | b=b | ||
4 | c=c | ||
5 | # Second assignment depends on the first: | ||
6 | b=$a c=$b | ||
7 | echo Assignments only: c=$c | ||
8 | |||
9 | b=b | ||
10 | c=c | ||
11 | b=$a c=$b "$THIS_SH" -c 'echo Assignments and a command: c=$c' | ||
12 | |||
13 | b=b | ||
14 | c=c | ||
15 | b=$a c=$b eval 'echo Assignments and a builtin: c=$c' | ||
16 | |||
17 | b=b | ||
18 | c=c | ||
19 | f() { echo Assignments and a function: c=$c; } | ||
20 | b=$a c=$b f | ||
21 | |||
22 | echo Done | ||
diff --git a/shell/ash_test/ash-vars/var_subst_in_for.right b/shell/ash_test/ash-vars/var_subst_in_for.right new file mode 100644 index 000000000..c8aca1c12 --- /dev/null +++ b/shell/ash_test/ash-vars/var_subst_in_for.right | |||
@@ -0,0 +1,40 @@ | |||
1 | Testing: in x y z | ||
2 | .x. | ||
3 | .y. | ||
4 | .z. | ||
5 | Testing: in u $empty v | ||
6 | .u. | ||
7 | .v. | ||
8 | Testing: in u " $empty" v | ||
9 | .u. | ||
10 | . . | ||
11 | .v. | ||
12 | Testing: in u $empty $empty$a v | ||
13 | .u. | ||
14 | .a. | ||
15 | .v. | ||
16 | Testing: in $a_b | ||
17 | .a. | ||
18 | .b. | ||
19 | Testing: in $* | ||
20 | .abc. | ||
21 | .d. | ||
22 | .e. | ||
23 | Testing: in $@ | ||
24 | .abc. | ||
25 | .d. | ||
26 | .e. | ||
27 | Testing: in -$*- | ||
28 | .-abc. | ||
29 | .d. | ||
30 | .e-. | ||
31 | Testing: in -$@- | ||
32 | .-abc. | ||
33 | .d. | ||
34 | .e-. | ||
35 | Testing: in $a_b -$a_b- | ||
36 | .a. | ||
37 | .b. | ||
38 | .-a. | ||
39 | .b-. | ||
40 | Finished | ||
diff --git a/shell/ash_test/ash-vars/var_subst_in_for.tests b/shell/ash_test/ash-vars/var_subst_in_for.tests new file mode 100755 index 000000000..433c60627 --- /dev/null +++ b/shell/ash_test/ash-vars/var_subst_in_for.tests | |||
@@ -0,0 +1,40 @@ | |||
1 | if test $# = 0; then | ||
2 | exec "$THIS_SH" "$0" abc "d e" | ||
3 | fi | ||
4 | |||
5 | echo 'Testing: in x y z' | ||
6 | for a in x y z; do echo ".$a."; done | ||
7 | |||
8 | echo 'Testing: in u $empty v' | ||
9 | empty='' | ||
10 | for a in u $empty v; do echo ".$a."; done | ||
11 | |||
12 | echo 'Testing: in u " $empty" v' | ||
13 | empty='' | ||
14 | for a in u " $empty" v; do echo ".$a."; done | ||
15 | |||
16 | echo 'Testing: in u $empty $empty$a v' | ||
17 | a='a' | ||
18 | for a in u $empty $empty$a v; do echo ".$a."; done | ||
19 | |||
20 | echo 'Testing: in $a_b' | ||
21 | a_b='a b' | ||
22 | for a in $a_b; do echo ".$a."; done | ||
23 | |||
24 | echo 'Testing: in $*' | ||
25 | for a in $*; do echo ".$a."; done | ||
26 | |||
27 | echo 'Testing: in $@' | ||
28 | for a in $@; do echo ".$a."; done | ||
29 | |||
30 | echo 'Testing: in -$*-' | ||
31 | for a in -$*-; do echo ".$a."; done | ||
32 | |||
33 | echo 'Testing: in -$@-' | ||
34 | for a in -$@-; do echo ".$a."; done | ||
35 | |||
36 | echo 'Testing: in $a_b -$a_b-' | ||
37 | a_b='a b' | ||
38 | for a in $a_b -$a_b-; do echo ".$a."; done | ||
39 | |||
40 | echo Finished | ||
diff --git a/shell/ash_test/ash-vars/var_unbackslash.right b/shell/ash_test/ash-vars/var_unbackslash.right new file mode 100644 index 000000000..8bc834711 --- /dev/null +++ b/shell/ash_test/ash-vars/var_unbackslash.right | |||
@@ -0,0 +1,11 @@ | |||
1 | b1=-qwerty-t-\-"-`---z-*-?- | ||
2 | b1=-qwerty-t-\-"-`---z-*-?- | ||
3 | b2=-qwerty-\t-\-"-`-\--\z-\*-\?- | ||
4 | b2=-qwerty-\t-\-"-`-\--\z-\*-\?- | ||
5 | b3=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
6 | b3=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
7 | c=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
8 | c=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
9 | c=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
10 | c=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
11 | Done: 0 | ||
diff --git a/shell/ash_test/ash-vars/var_unbackslash.tests b/shell/ash_test/ash-vars/var_unbackslash.tests new file mode 100755 index 000000000..bb52af3d0 --- /dev/null +++ b/shell/ash_test/ash-vars/var_unbackslash.tests | |||
@@ -0,0 +1,23 @@ | |||
1 | # Test for correct handling of backslashes | ||
2 | a=qwerty | ||
3 | |||
4 | b=-$a-\t-\\-\"-\`-\--\z-\*-\?- | ||
5 | echo b1=$b | ||
6 | echo "b1=$b" | ||
7 | b="-$a-\t-\\-\"-\`-\--\z-\*-\?-" | ||
8 | echo b2=$b | ||
9 | echo "b2=$b" | ||
10 | b='-$a-\t-\\-\"-\`-\--\z-\*-\?-' | ||
11 | echo b3=$b | ||
12 | echo "b3=$b" | ||
13 | |||
14 | c=$b | ||
15 | echo "c=$c" | ||
16 | c=${b} | ||
17 | echo "c=$c" | ||
18 | c="$b" | ||
19 | echo "c=$c" | ||
20 | c="${b}" | ||
21 | echo "c=$c" | ||
22 | |||
23 | echo "Done: $?" | ||
diff --git a/shell/ash_test/ash-vars/var_unbackslash1.right b/shell/ash_test/ash-vars/var_unbackslash1.right new file mode 100644 index 000000000..8d4eca34e --- /dev/null +++ b/shell/ash_test/ash-vars/var_unbackslash1.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Ok | ||
2 | Ba d | ||
3 | Ok | ||
diff --git a/shell/ash_test/ash-vars/var_unbackslash1.tests b/shell/ash_test/ash-vars/var_unbackslash1.tests new file mode 100755 index 000000000..8a9f2e249 --- /dev/null +++ b/shell/ash_test/ash-vars/var_unbackslash1.tests | |||
@@ -0,0 +1,15 @@ | |||
1 | ad="Ok" | ||
2 | a="Ba" | ||
3 | |||
4 | # "Ok" | ||
5 | echo $a\ | ||
6 | d | ||
7 | |||
8 | # This variable contains backslash+newline! | ||
9 | e='echo $a\ | ||
10 | d' | ||
11 | |||
12 | # "Ba d" | ||
13 | eval $e | ||
14 | # "Ok" | ||
15 | eval "$e" | ||
diff --git a/shell/hush_test/hush-vars/var_unbackslash1.right b/shell/hush_test/hush-vars/var_unbackslash1.right new file mode 100644 index 000000000..8d4eca34e --- /dev/null +++ b/shell/hush_test/hush-vars/var_unbackslash1.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Ok | ||
2 | Ba d | ||
3 | Ok | ||
diff --git a/shell/hush_test/hush-vars/var_unbackslash1.tests b/shell/hush_test/hush-vars/var_unbackslash1.tests new file mode 100755 index 000000000..8a9f2e249 --- /dev/null +++ b/shell/hush_test/hush-vars/var_unbackslash1.tests | |||
@@ -0,0 +1,15 @@ | |||
1 | ad="Ok" | ||
2 | a="Ba" | ||
3 | |||
4 | # "Ok" | ||
5 | echo $a\ | ||
6 | d | ||
7 | |||
8 | # This variable contains backslash+newline! | ||
9 | e='echo $a\ | ||
10 | d' | ||
11 | |||
12 | # "Ba d" | ||
13 | eval $e | ||
14 | # "Ok" | ||
15 | eval "$e" | ||