diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-11 20:00:43 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-11 20:00:43 +0200 |
commit | f693b606b732437bb1265c2ec883d93127f3f38e (patch) | |
tree | 921ed6a5ada75f8d608f139eecd211f0f5869eb9 | |
parent | 44257ad5d0790a846423c9ef69a50049366b4578 (diff) | |
download | busybox-w32-f693b606b732437bb1265c2ec883d93127f3f38e.tar.gz busybox-w32-f693b606b732437bb1265c2ec883d93127f3f38e.tar.bz2 busybox-w32-f693b606b732437bb1265c2ec883d93127f3f38e.zip |
hush: fix recent breakage from parse_stream() changes
function old new delta
parse_stream 3808 3821 +13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash_test/ash-parsing/bkslash_newline3.right | 1 | ||||
-rwxr-xr-x | shell/ash_test/ash-parsing/bkslash_newline3.tests | 4 | ||||
-rw-r--r-- | shell/hush.c | 44 | ||||
-rw-r--r-- | shell/hush_test/hush-parsing/bkslash_newline3.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-parsing/bkslash_newline3.tests | 4 |
5 files changed, 32 insertions, 22 deletions
diff --git a/shell/ash_test/ash-parsing/bkslash_newline3.right b/shell/ash_test/ash-parsing/bkslash_newline3.right new file mode 100644 index 000000000..e635074e5 --- /dev/null +++ b/shell/ash_test/ash-parsing/bkslash_newline3.right | |||
@@ -0,0 +1 @@ | |||
a:[a] | |||
diff --git a/shell/ash_test/ash-parsing/bkslash_newline3.tests b/shell/ash_test/ash-parsing/bkslash_newline3.tests new file mode 100755 index 000000000..2accd4395 --- /dev/null +++ b/shell/ash_test/ash-parsing/bkslash_newline3.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | for s in \ | ||
2 | a; do | ||
3 | echo "a:[$s]" | ||
4 | done | ||
diff --git a/shell/hush.c b/shell/hush.c index 8e95a26a6..c77700175 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5075,7 +5075,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5075 | debug_printf_parse("parse_stream return %p\n", pi); | 5075 | debug_printf_parse("parse_stream return %p\n", pi); |
5076 | return pi; | 5076 | return pi; |
5077 | } | 5077 | } |
5078 | nommu_addchr(&ctx.as_string, ch); | ||
5079 | 5078 | ||
5080 | /* Handle "'" and "\" first, as they won't play nice with | 5079 | /* Handle "'" and "\" first, as they won't play nice with |
5081 | * i_peek_and_eat_bkslash_nl() anyway: | 5080 | * i_peek_and_eat_bkslash_nl() anyway: |
@@ -5085,6 +5084,28 @@ static struct pipe *parse_stream(char **pstring, | |||
5085 | * ' | 5084 | * ' |
5086 | * would break. | 5085 | * would break. |
5087 | */ | 5086 | */ |
5087 | if (ch == '\\') { | ||
5088 | ch = i_getch(input); | ||
5089 | if (ch == '\n') | ||
5090 | continue; /* drop \<newline>, get next char */ | ||
5091 | nommu_addchr(&ctx.as_string, '\\'); | ||
5092 | o_addchr(&ctx.word, '\\'); | ||
5093 | if (ch == EOF) { | ||
5094 | /* Testcase: eval 'echo Ok\' */ | ||
5095 | /* bash-4.3.43 was removing backslash, | ||
5096 | * but 4.4.19 retains it, most other shells too | ||
5097 | */ | ||
5098 | continue; /* get next char */ | ||
5099 | } | ||
5100 | /* Example: echo Hello \2>file | ||
5101 | * we need to know that word 2 is quoted | ||
5102 | */ | ||
5103 | ctx.word.has_quoted_part = 1; | ||
5104 | nommu_addchr(&ctx.as_string, ch); | ||
5105 | o_addchr(&ctx.word, ch); | ||
5106 | continue; /* get next char */ | ||
5107 | } | ||
5108 | nommu_addchr(&ctx.as_string, ch); | ||
5088 | if (ch == '\'') { | 5109 | if (ch == '\'') { |
5089 | ctx.word.has_quoted_part = 1; | 5110 | ctx.word.has_quoted_part = 1; |
5090 | next = i_getch(input); | 5111 | next = i_getch(input); |
@@ -5110,27 +5131,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5110 | } | 5131 | } |
5111 | continue; /* get next char */ | 5132 | continue; /* get next char */ |
5112 | } | 5133 | } |
5113 | if (ch == '\\') { | ||
5114 | /*nommu_addchr(&ctx.as_string, '\\'); - already done */ | ||
5115 | o_addchr(&ctx.word, '\\'); | ||
5116 | ch = i_getch(input); | ||
5117 | if (ch == EOF) { | ||
5118 | /* Testcase: eval 'echo Ok\' */ | ||
5119 | |||
5120 | #if 0 /* bash-4.3.43 was removing backslash, but 4.4.19 retains it, most other shells too */ | ||
5121 | /* Remove trailing '\' from ctx.as_string */ | ||
5122 | ctx.as_string.data[--ctx.as_string.length] = '\0'; | ||
5123 | #endif | ||
5124 | continue; /* get next char */ | ||
5125 | } | ||
5126 | /* Example: echo Hello \2>file | ||
5127 | * we need to know that word 2 is quoted | ||
5128 | */ | ||
5129 | ctx.word.has_quoted_part = 1; | ||
5130 | nommu_addchr(&ctx.as_string, ch); | ||
5131 | o_addchr(&ctx.word, ch); | ||
5132 | continue; /* get next char */ | ||
5133 | } | ||
5134 | 5134 | ||
5135 | next = '\0'; | 5135 | next = '\0'; |
5136 | if (ch != '\n') | 5136 | if (ch != '\n') |
diff --git a/shell/hush_test/hush-parsing/bkslash_newline3.right b/shell/hush_test/hush-parsing/bkslash_newline3.right new file mode 100644 index 000000000..e635074e5 --- /dev/null +++ b/shell/hush_test/hush-parsing/bkslash_newline3.right | |||
@@ -0,0 +1 @@ | |||
a:[a] | |||
diff --git a/shell/hush_test/hush-parsing/bkslash_newline3.tests b/shell/hush_test/hush-parsing/bkslash_newline3.tests new file mode 100755 index 000000000..2accd4395 --- /dev/null +++ b/shell/hush_test/hush-parsing/bkslash_newline3.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | for s in \ | ||
2 | a; do | ||
3 | echo "a:[$s]" | ||
4 | done | ||