summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko2008-07-31 10:09:26 +0000
committerDenis Vlasenko2008-07-31 10:09:26 +0000
commitf173607520e0455d267a7a4100e5018f30000c56 (patch)
tree6699a09a57e45890ac07eb4ec2964f9ed7486230
parentfbeeb328b8a2e0006f9a53ddea6892f9c1a03132 (diff)
downloadbusybox-f173607520e0455d267a7a4100e5018f30000c56.zip
busybox-f173607520e0455d267a7a4100e5018f30000c56.tar.gz
hush: fix "case ... in <newline> word)..."
-rw-r--r--shell/hush.c12
-rw-r--r--shell/hush_test/hush-misc/case1.right1
-rwxr-xr-xshell/hush_test/hush-misc/case1.tests8
3 files changed, 20 insertions, 1 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 564b62c..8be0ecf 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3659,6 +3659,15 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
* a newline as a command separator.
* [why we don't handle it exactly like ';'? --vda] */
if (end_trigger && ch == '\n') {
+#if ENABLE_HUSH_CASE
+ /* "case ... in <newline> word) ..." -
+ * newlines are ignored (but ';' wouldn't be) */
+ if (dest->length == 0 // && argv[0] == NULL
+ && ctx->ctx_res_w == RES_MATCH
+ ) {
+ continue;
+ }
+#endif
done_pipe(ctx, PIPE_SEQ);
}
}
@@ -3839,7 +3848,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
done_word(dest, ctx);
#if ENABLE_HUSH_CASE
if (ctx->ctx_res_w == RES_MATCH)
- break;
+ break; /* we are in case's "word | word)" */
#endif
if (next == '|') {
i_getch(input);
@@ -3853,6 +3862,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
break;
case '(':
#if ENABLE_HUSH_CASE
+ /* "case... in [(]word)..." - skip '(' */
if (dest->length == 0 // && argv[0] == NULL
&& ctx->ctx_res_w == RES_MATCH
) {
diff --git a/shell/hush_test/hush-misc/case1.right b/shell/hush_test/hush-misc/case1.right
index 9b88658..e9e371a 100644
--- a/shell/hush_test/hush-misc/case1.right
+++ b/shell/hush_test/hush-misc/case1.right
@@ -1,4 +1,5 @@
OK_1
+OK_1
OK_21
OK_22
OK_23
diff --git a/shell/hush_test/hush-misc/case1.tests b/shell/hush_test/hush-misc/case1.tests
index 15f60f3..0174893 100755
--- a/shell/hush_test/hush-misc/case1.tests
+++ b/shell/hush_test/hush-misc/case1.tests
@@ -1,5 +1,13 @@
case w in a) echo SKIP;; w) echo OK_1;; w) echo WRONG;; esac
+case w in
+ a) echo SKIP;;
+ w)echo OK_1 ;;
+ w)
+ echo WRONG
+ ;;
+esac
+
t=w
case $t in a) echo SKIP;; w) echo OK_21;; w) echo WRONG;; esac;
case "$t" in a) echo SKIP;; w) echo OK_22;; w) echo WRONG;; esac;