diff options
-rw-r--r-- | shell/hush.c | 14 | ||||
-rw-r--r-- | shell/hush_test/hush-parsing/starquoted2.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-parsing/starquoted2.tests | 3 |
3 files changed, 16 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c index e6189f841..bfd487cfb 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1219,8 +1219,13 @@ static int o_glob(o_string *o, int n) | |||
1219 | * Otherwise, just finish current list[] and start new */ | 1219 | * Otherwise, just finish current list[] and start new */ |
1220 | static int o_save_ptr(o_string *o, int n) | 1220 | static int o_save_ptr(o_string *o, int n) |
1221 | { | 1221 | { |
1222 | if (o->o_glob) | 1222 | if (o->o_glob) { /* if globbing is requested */ |
1223 | return o_glob(o, n); /* o_save_ptr_helper is inside */ | 1223 | /* If o->has_empty_slot, list[n] was already globbed |
1224 | * (if it was requested back then when it was filled) | ||
1225 | * so don't do that again! */ | ||
1226 | if (!o->has_empty_slot) | ||
1227 | return o_glob(o, n); /* o_save_ptr_helper is inside */ | ||
1228 | } | ||
1224 | return o_save_ptr_helper(o, n); | 1229 | return o_save_ptr_helper(o, n); |
1225 | } | 1230 | } |
1226 | 1231 | ||
@@ -4285,6 +4290,11 @@ int hush_main(int argc, char **argv) | |||
4285 | switch (opt) { | 4290 | switch (opt) { |
4286 | case 'c': | 4291 | case 'c': |
4287 | G.global_argv = argv + optind; | 4292 | G.global_argv = argv + optind; |
4293 | if (!argv[optind]) { | ||
4294 | /* -c 'script' (no params): prevent empty $0 */ | ||
4295 | *--G.global_argv = argv[0]; | ||
4296 | optind--; | ||
4297 | } /* else -c 'script' PAR0 PAR1: $0 is PAR0 */ | ||
4288 | G.global_argc = argc - optind; | 4298 | G.global_argc = argc - optind; |
4289 | opt = parse_and_run_string(optarg, 0 /* parse_flag */); | 4299 | opt = parse_and_run_string(optarg, 0 /* parse_flag */); |
4290 | goto final_return; | 4300 | goto final_return; |
diff --git a/shell/hush_test/hush-parsing/starquoted2.right b/shell/hush_test/hush-parsing/starquoted2.right index 46f24369e..f4624dad5 100644 --- a/shell/hush_test/hush-parsing/starquoted2.right +++ b/shell/hush_test/hush-parsing/starquoted2.right | |||
@@ -1,2 +1,3 @@ | |||
1 | Should be printed | 1 | Should be printed |
2 | Should be printed | 2 | Should be printed |
3 | Empty: | ||
diff --git a/shell/hush_test/hush-parsing/starquoted2.tests b/shell/hush_test/hush-parsing/starquoted2.tests index 782d71b88..3475edeb2 100755 --- a/shell/hush_test/hush-parsing/starquoted2.tests +++ b/shell/hush_test/hush-parsing/starquoted2.tests | |||
@@ -12,3 +12,6 @@ for a in "$@"""; do echo Should not be printed; done | |||
12 | for a in """$@"; do echo Should not be printed; done | 12 | for a in """$@"; do echo Should not be printed; done |
13 | for a in """$@"''"$@"''; do echo Should not be printed; done | 13 | for a in """$@"''"$@"''; do echo Should not be printed; done |
14 | for a in ""; do echo Should be printed; done | 14 | for a in ""; do echo Should be printed; done |
15 | |||
16 | # Bug 207: "$@" expands to nothing, and we erroneously glob "%s\\n" twice: | ||
17 | printf "Empty:%s\\n" "$@" | ||