diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-05 23:12:15 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-05 23:12:15 +0200 |
commit | bd43c6784fb53826806c7cb51a1ed54e95eb4be9 (patch) | |
tree | 8b250b2eaa4781af90a4c4b6702903b11cdf7f24 | |
parent | 4142f0187dcf8454e8d2a8d16b321dbd573c170e (diff) | |
download | busybox-w32-bd43c6784fb53826806c7cb51a1ed54e95eb4be9.tar.gz busybox-w32-bd43c6784fb53826806c7cb51a1ed54e95eb4be9.tar.bz2 busybox-w32-bd43c6784fb53826806c7cb51a1ed54e95eb4be9.zip |
hush: fix quoted_punct.tests failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | shell/hush_test/hush-quoting/quoted_punct.right | 35 | ||||
-rwxr-xr-x | shell/hush_test/hush-quoting/quoted_punct.tests | 41 |
4 files changed, 83 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c index 946e8726e..b7635a823 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -7613,7 +7613,9 @@ expandhere(union node *arg, int fd) | |||
7613 | static int | 7613 | static int |
7614 | patmatch(char *pattern, const char *string) | 7614 | patmatch(char *pattern, const char *string) |
7615 | { | 7615 | { |
7616 | return pmatch(preglob(pattern, 0), string); | 7616 | char *p = preglob(pattern, 0); |
7617 | //bb_error_msg("fnmatch(pattern:'%s',str:'%s')", p, string); | ||
7618 | return pmatch(p, string); | ||
7617 | } | 7619 | } |
7618 | 7620 | ||
7619 | /* | 7621 | /* |
diff --git a/shell/hush.c b/shell/hush.c index 30add72f0..7574e3918 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5969,7 +5969,7 @@ static char *expand_string_to_string(const char *str, int do_unbackslash) | |||
5969 | return (char*)list; | 5969 | return (char*)list; |
5970 | } | 5970 | } |
5971 | 5971 | ||
5972 | /* Used for "eval" builtin */ | 5972 | /* Used for "eval" builtin and case string */ |
5973 | static char* expand_strvec_to_string(char **argv) | 5973 | static char* expand_strvec_to_string(char **argv) |
5974 | { | 5974 | { |
5975 | char **list; | 5975 | char **list; |
@@ -8053,6 +8053,7 @@ static int run_list(struct pipe *pi) | |||
8053 | if (rword == RES_CASE) { | 8053 | if (rword == RES_CASE) { |
8054 | debug_printf_exec("CASE cond_code:%d\n", cond_code); | 8054 | debug_printf_exec("CASE cond_code:%d\n", cond_code); |
8055 | case_word = expand_strvec_to_string(pi->cmds->argv); | 8055 | case_word = expand_strvec_to_string(pi->cmds->argv); |
8056 | unbackslash(case_word); | ||
8056 | continue; | 8057 | continue; |
8057 | } | 8058 | } |
8058 | if (rword == RES_MATCH) { | 8059 | if (rword == RES_MATCH) { |
@@ -8064,9 +8065,10 @@ static int run_list(struct pipe *pi) | |||
8064 | /* all prev words didn't match, does this one match? */ | 8065 | /* all prev words didn't match, does this one match? */ |
8065 | argv = pi->cmds->argv; | 8066 | argv = pi->cmds->argv; |
8066 | while (*argv) { | 8067 | while (*argv) { |
8067 | char *pattern = expand_string_to_string(*argv, /*unbackslash:*/ 1); | 8068 | char *pattern = expand_string_to_string(*argv, /*unbackslash:*/ 0); |
8068 | /* TODO: which FNM_xxx flags to use? */ | 8069 | /* TODO: which FNM_xxx flags to use? */ |
8069 | cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); | 8070 | cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); |
8071 | debug_printf_exec("fnmatch(pattern:'%s',str:'%s'):%d\n", pattern, case_word, cond_code); | ||
8070 | free(pattern); | 8072 | free(pattern); |
8071 | if (cond_code == 0) { /* match! we will execute this branch */ | 8073 | if (cond_code == 0) { /* match! we will execute this branch */ |
8072 | free(case_word); | 8074 | free(case_word); |
diff --git a/shell/hush_test/hush-quoting/quoted_punct.right b/shell/hush_test/hush-quoting/quoted_punct.right new file mode 100644 index 000000000..ab66c3ce0 --- /dev/null +++ b/shell/hush_test/hush-quoting/quoted_punct.right | |||
@@ -0,0 +1,35 @@ | |||
1 | ok | ||
2 | ok | ||
3 | ok | ||
4 | ok | ||
5 | ok | ||
6 | ok | ||
7 | ok | ||
8 | ok | ||
9 | ok | ||
10 | ok | ||
11 | ok | ||
12 | ok | ||
13 | ok | ||
14 | ok | ||
15 | ok | ||
16 | ok | ||
17 | ok | ||
18 | ok | ||
19 | ok | ||
20 | ok | ||
21 | ok | ||
22 | ok | ||
23 | ok | ||
24 | ok | ||
25 | ok | ||
26 | ok | ||
27 | ok | ||
28 | ok | ||
29 | ok | ||
30 | ok | ||
31 | ok | ||
32 | ok | ||
33 | ok | ||
34 | ok | ||
35 | ok | ||
diff --git a/shell/hush_test/hush-quoting/quoted_punct.tests b/shell/hush_test/hush-quoting/quoted_punct.tests new file mode 100755 index 000000000..83ee40bf4 --- /dev/null +++ b/shell/hush_test/hush-quoting/quoted_punct.tests | |||
@@ -0,0 +1,41 @@ | |||
1 | # Testing glob-escaping of every ASCII punctuation char | ||
2 | # Some chars have more than one test | ||
3 | # 21..2f | ||
4 | case '!' in [\!] ) echo ok;; *) echo 'WRONG!';; esac | ||
5 | case '"' in [\"] ) echo ok;; *) echo 'WRONG"';; esac | ||
6 | case '#' in [\#] ) echo ok;; *) echo 'WRONG#';; esac | ||
7 | case '$' in [\$] ) echo ok;; *) echo 'WRONG$';; esac | ||
8 | case '%' in [\%] ) echo ok;; *) echo 'WRONG%';; esac | ||
9 | case '&' in [\&] ) echo ok;; *) echo 'WRONG&';; esac | ||
10 | case "'" in [\'] ) echo ok;; *) echo "WRONG'";; esac | ||
11 | case '(' in [\(] ) echo ok;; *) echo 'WRONG(';; esac | ||
12 | case ')' in [\)] ) echo ok;; *) echo 'WRONG)';; esac | ||
13 | case '*' in [\*] ) echo ok;; *) echo 'WRONG*';; esac | ||
14 | case '+' in [\+] ) echo ok;; *) echo 'WRONG+';; esac | ||
15 | case ',' in [\,] ) echo ok;; *) echo 'WRONG,';; esac | ||
16 | case '-' in [\-] ) echo ok;; *) echo 'WRONG-';; esac | ||
17 | case '-' in [a\-c]) echo ok;; *) echo 'WRONGa\-c';; esac | ||
18 | case '.' in [\.] ) echo ok;; *) echo 'WRONG.';; esac | ||
19 | case '/' in [\/] ) echo ok;; *) echo 'WRONG/';; esac | ||
20 | # 3a..40 | ||
21 | case ':' in [\:] ) echo ok;; *) echo 'WRONG:';; esac | ||
22 | case ';' in [\;] ) echo ok;; *) echo 'WRONG;';; esac | ||
23 | case '<' in [\<] ) echo ok;; *) echo 'WRONG<';; esac | ||
24 | case '=' in [\=] ) echo ok;; *) echo 'WRONG=';; esac | ||
25 | case '>' in [\>] ) echo ok;; *) echo 'WRONG>';; esac | ||
26 | case '?' in [\?] ) echo ok;; *) echo 'WRONG?';; esac | ||
27 | case '@' in [\@] ) echo ok;; *) echo 'WRONG@';; esac | ||
28 | # 5b..60 | ||
29 | case '[' in [\[] ) echo ok;; *) echo 'WRONG[';; esac | ||
30 | case '\' in [\\] ) echo ok;; *) echo 'WRONG\';; esac | ||
31 | case '\' in \\ ) echo ok;; *) echo 'WRONG\\';; esac | ||
32 | case ']' in [\]] ) echo ok;; *) echo 'WRONG]';; esac | ||
33 | case ']' in [a\]]) echo ok;; *) echo 'WRONGa]';; esac | ||
34 | case '^' in [\^] ) echo ok;; *) echo 'WRONG^';; esac | ||
35 | case '_' in [\_] ) echo ok;; *) echo 'WRONG_';; esac | ||
36 | case '`' in [\`] ) echo ok;; *) echo 'WRONG`';; esac | ||
37 | # 7b..7e | ||
38 | case '{' in [\{] ) echo ok;; *) echo 'WRONG{';; esac | ||
39 | case '|' in [\|] ) echo ok;; *) echo 'WRONG|';; esac | ||
40 | case '}' in [\}] ) echo ok;; *) echo 'WRONG}';; esac | ||
41 | case '~' in [\~] ) echo ok;; *) echo 'WRONG~';; esac | ||