diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-02 20:48:36 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-02 20:48:36 +0100 |
commit | d4802c6243e64e28690577bc0bb4f030581c496b (patch) | |
tree | e1b3785c46bd4361419fb22718b319cf3a835658 /shell | |
parent | 55f8133a4fb207d6fecd02f43c36809d3c2f6672 (diff) | |
download | busybox-w32-d4802c6243e64e28690577bc0bb4f030581c496b.tar.gz busybox-w32-d4802c6243e64e28690577bc0bb4f030581c496b.tar.bz2 busybox-w32-d4802c6243e64e28690577bc0bb4f030581c496b.zip |
hush: fix a='a\\'; echo "${a%\\\\}"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash_test/ash-quoting/squote_in_varexp1.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/squote_in_varexp1.tests | 4 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/squote_in_varexp2.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/squote_in_varexp2.tests | 4 | ||||
-rw-r--r-- | shell/hush.c | 12 | ||||
-rw-r--r-- | shell/hush_test/hush-quoting/squote_in_varexp1.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-quoting/squote_in_varexp1.tests | 4 | ||||
-rw-r--r-- | shell/hush_test/hush-quoting/squote_in_varexp2.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-quoting/squote_in_varexp2.tests | 4 | ||||
-rw-r--r-- | shell/match.c | 2 |
10 files changed, 39 insertions, 3 deletions
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp1.right b/shell/ash_test/ash-quoting/squote_in_varexp1.right new file mode 100644 index 000000000..9d0add3c5 --- /dev/null +++ b/shell/ash_test/ash-quoting/squote_in_varexp1.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Nothing: | ||
2 | Nothing: | ||
3 | Ok:0 | ||
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp1.tests b/shell/ash_test/ash-quoting/squote_in_varexp1.tests new file mode 100755 index 000000000..efb380db3 --- /dev/null +++ b/shell/ash_test/ash-quoting/squote_in_varexp1.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | x='\\\\' | ||
2 | printf Nothing:'%s\n' ${x#\\\\\\\\} | ||
3 | printf Nothing:'%s\n' "${x#\\\\\\\\}" | ||
4 | echo Ok:$? | ||
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp2.right b/shell/ash_test/ash-quoting/squote_in_varexp2.right new file mode 100644 index 000000000..9d0add3c5 --- /dev/null +++ b/shell/ash_test/ash-quoting/squote_in_varexp2.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Nothing: | ||
2 | Nothing: | ||
3 | Ok:0 | ||
diff --git a/shell/ash_test/ash-quoting/squote_in_varexp2.tests b/shell/ash_test/ash-quoting/squote_in_varexp2.tests new file mode 100755 index 000000000..806ad12b9 --- /dev/null +++ b/shell/ash_test/ash-quoting/squote_in_varexp2.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | x='\\\\' | ||
2 | printf Nothing:'%s\n' ${x#'\\\\'} | ||
3 | printf Nothing:'%s\n' "${x#'\\\\'}" | ||
4 | echo Ok:$? | ||
diff --git a/shell/hush.c b/shell/hush.c index da4967a8a..762cc3fe4 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -4500,6 +4500,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign | |||
4500 | } | 4500 | } |
4501 | } | 4501 | } |
4502 | o_addchr(dest, ch); | 4502 | o_addchr(dest, ch); |
4503 | //bb_error_msg("%s:o_addchr('%c')", __func__, ch); | ||
4503 | if (ch == '(' || ch == '{') { | 4504 | if (ch == '(' || ch == '{') { |
4504 | ch = (ch == '(' ? ')' : '}'); | 4505 | ch = (ch == '(' ? ')' : '}'); |
4505 | if (!add_till_closing_bracket(dest, input, ch)) | 4506 | if (!add_till_closing_bracket(dest, input, ch)) |
@@ -4529,7 +4530,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign | |||
4529 | /* \x. Copy verbatim. Important for \(, \) */ | 4530 | /* \x. Copy verbatim. Important for \(, \) */ |
4530 | ch = i_getch(input); | 4531 | ch = i_getch(input); |
4531 | if (ch == EOF) { | 4532 | if (ch == EOF) { |
4532 | syntax_error_unterm_ch(')'); | 4533 | syntax_error_unterm_ch(end_ch); |
4533 | return 0; | 4534 | return 0; |
4534 | } | 4535 | } |
4535 | #if 0 | 4536 | #if 0 |
@@ -4540,6 +4541,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign | |||
4540 | } | 4541 | } |
4541 | #endif | 4542 | #endif |
4542 | o_addchr(dest, ch); | 4543 | o_addchr(dest, ch); |
4544 | //bb_error_msg("%s:o_addchr('%c') after '\\'", __func__, ch); | ||
4543 | continue; | 4545 | continue; |
4544 | } | 4546 | } |
4545 | } | 4547 | } |
@@ -5843,7 +5845,13 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
5843 | if (exp_op == *exp_word) /* ## or %% */ | 5845 | if (exp_op == *exp_word) /* ## or %% */ |
5844 | exp_word++; | 5846 | exp_word++; |
5845 | debug_printf_expand("expand: exp_word:'%s'\n", exp_word); | 5847 | debug_printf_expand("expand: exp_word:'%s'\n", exp_word); |
5846 | exp_exp_word = encode_then_expand_string(exp_word, /*process_bkslash:*/ 1, /*unbackslash:*/ 1); | 5848 | /* |
5849 | * process_bkslash:1 unbackslash:1 breaks this: | ||
5850 | * a='a\\'; echo ${a%\\\\} # correct output is: a | ||
5851 | * process_bkslash:1 unbackslash:0 breaks this: | ||
5852 | * a='a}'; echo ${a%\}} # correct output is: a | ||
5853 | */ | ||
5854 | exp_exp_word = encode_then_expand_string(exp_word, /*process_bkslash:*/ 0, /*unbackslash:*/ 0); | ||
5847 | if (exp_exp_word) | 5855 | if (exp_exp_word) |
5848 | exp_word = exp_exp_word; | 5856 | exp_word = exp_exp_word; |
5849 | debug_printf_expand("expand: exp_exp_word:'%s'\n", exp_word); | 5857 | debug_printf_expand("expand: exp_exp_word:'%s'\n", exp_word); |
diff --git a/shell/hush_test/hush-quoting/squote_in_varexp1.right b/shell/hush_test/hush-quoting/squote_in_varexp1.right new file mode 100644 index 000000000..9d0add3c5 --- /dev/null +++ b/shell/hush_test/hush-quoting/squote_in_varexp1.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Nothing: | ||
2 | Nothing: | ||
3 | Ok:0 | ||
diff --git a/shell/hush_test/hush-quoting/squote_in_varexp1.tests b/shell/hush_test/hush-quoting/squote_in_varexp1.tests new file mode 100755 index 000000000..efb380db3 --- /dev/null +++ b/shell/hush_test/hush-quoting/squote_in_varexp1.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | x='\\\\' | ||
2 | printf Nothing:'%s\n' ${x#\\\\\\\\} | ||
3 | printf Nothing:'%s\n' "${x#\\\\\\\\}" | ||
4 | echo Ok:$? | ||
diff --git a/shell/hush_test/hush-quoting/squote_in_varexp2.right b/shell/hush_test/hush-quoting/squote_in_varexp2.right new file mode 100644 index 000000000..9d0add3c5 --- /dev/null +++ b/shell/hush_test/hush-quoting/squote_in_varexp2.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Nothing: | ||
2 | Nothing: | ||
3 | Ok:0 | ||
diff --git a/shell/hush_test/hush-quoting/squote_in_varexp2.tests b/shell/hush_test/hush-quoting/squote_in_varexp2.tests new file mode 100755 index 000000000..806ad12b9 --- /dev/null +++ b/shell/hush_test/hush-quoting/squote_in_varexp2.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | x='\\\\' | ||
2 | printf Nothing:'%s\n' ${x#'\\\\'} | ||
3 | printf Nothing:'%s\n' "${x#'\\\\'}" | ||
4 | echo Ok:$? | ||
diff --git a/shell/match.c b/shell/match.c index 8f2a2fb38..ee8abb2db 100644 --- a/shell/match.c +++ b/shell/match.c | |||
@@ -75,7 +75,7 @@ char* FAST_FUNC scan_and_match(char *string, const char *pattern, unsigned flags | |||
75 | *loc = c; | 75 | *loc = c; |
76 | } else { | 76 | } else { |
77 | r = fnmatch(pattern, loc, 0); | 77 | r = fnmatch(pattern, loc, 0); |
78 | //bb_error_msg("fnmatch('%s','%s',0):%d", pattern, string, r); | 78 | //bb_error_msg("fnmatch('%s','%s',0):%d", pattern, loc, r); |
79 | } | 79 | } |
80 | if (r == 0) /* match found */ | 80 | if (r == 0) /* match found */ |
81 | return loc; | 81 | return loc; |