summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/ash_test/ash-misc/func6.right3
-rwxr-xr-xshell/ash_test/ash-misc/func6.tests8
-rw-r--r--shell/ash_test/ash-misc/func7.right1
-rwxr-xr-xshell/ash_test/ash-misc/func7.tests1
-rw-r--r--shell/hush.c13
-rw-r--r--shell/hush_test/hush-misc/func6.right3
-rwxr-xr-xshell/hush_test/hush-misc/func6.tests8
-rw-r--r--shell/hush_test/hush-misc/func7.right1
-rwxr-xr-xshell/hush_test/hush-misc/func7.tests1
9 files changed, 37 insertions, 2 deletions
diff --git a/shell/ash_test/ash-misc/func6.right b/shell/ash_test/ash-misc/func6.right
new file mode 100644
index 000000000..01e79c32a
--- /dev/null
+++ b/shell/ash_test/ash-misc/func6.right
@@ -0,0 +1,3 @@
+1
+2
+3
diff --git a/shell/ash_test/ash-misc/func6.tests b/shell/ash_test/ash-misc/func6.tests
new file mode 100755
index 000000000..5f1699c42
--- /dev/null
+++ b/shell/ash_test/ash-misc/func6.tests
@@ -0,0 +1,8 @@
+{ f() { echo $1; } }
+f 1
+
+{ f() ( echo $1; )}
+f 2
+
+{ f()(echo $1)}
+f 3
diff --git a/shell/ash_test/ash-misc/func7.right b/shell/ash_test/ash-misc/func7.right
new file mode 100644
index 000000000..7b24a35ff
--- /dev/null
+++ b/shell/ash_test/ash-misc/func7.right
@@ -0,0 +1 @@
+Ok:0
diff --git a/shell/ash_test/ash-misc/func7.tests b/shell/ash_test/ash-misc/func7.tests
new file mode 100755
index 000000000..f5e03b6e1
--- /dev/null
+++ b/shell/ash_test/ash-misc/func7.tests
@@ -0,0 +1 @@
+if f() { echo Ok:$?; } then f; fi
diff --git a/shell/hush.c b/shell/hush.c
index 8aa923e2e..226a6d68f 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -4469,7 +4469,12 @@ static int done_word(struct parse_context *ctx)
} else
# endif
/* Is it a place where keyword can appear? */
- if (!command->argv /* if it's the first word of command... */
+//FIXME: this is wrong, it allows invalid syntax: { echo t; } if true; then echo YES; fi
+ if ((!command->argv /* if it's the first word of command... */
+# if ENABLE_HUSH_FUNCTIONS
+ || command->cmd_type == CMD_FUNCDEF /* ^^^ or after FUNC() {} */
+# endif
+ )
&& !ctx->word.has_quoted_part /* ""WORD never matches any keywords */
&& !command->redirects /* no redirects yet... disallows: </dev/null if true; then... */
# if ENABLE_HUSH_LOOPS
@@ -6067,7 +6072,11 @@ static struct pipe *parse_stream(char **pstring,
} else
#endif
/* Are { and } special here? */
- if (ctx.command->argv /* WORD [WORD]{... - non-special */
+ if ((ctx.command->argv /* WORD [WORD]{... - non-special */
+#if ENABLE_HUSH_FUNCTIONS
+ && ctx.command->cmd_type != CMD_FUNCDEF /* ^^^ unless FUNC() {} */
+#endif
+ )
|| !IS_NULL_WORD(ctx.word) /* WORD{... ""{... - non-special */
|| (next != ';' /* }; - special */
&& next != ')' /* }) - special */
diff --git a/shell/hush_test/hush-misc/func6.right b/shell/hush_test/hush-misc/func6.right
new file mode 100644
index 000000000..01e79c32a
--- /dev/null
+++ b/shell/hush_test/hush-misc/func6.right
@@ -0,0 +1,3 @@
+1
+2
+3
diff --git a/shell/hush_test/hush-misc/func6.tests b/shell/hush_test/hush-misc/func6.tests
new file mode 100755
index 000000000..5f1699c42
--- /dev/null
+++ b/shell/hush_test/hush-misc/func6.tests
@@ -0,0 +1,8 @@
+{ f() { echo $1; } }
+f 1
+
+{ f() ( echo $1; )}
+f 2
+
+{ f()(echo $1)}
+f 3
diff --git a/shell/hush_test/hush-misc/func7.right b/shell/hush_test/hush-misc/func7.right
new file mode 100644
index 000000000..7b24a35ff
--- /dev/null
+++ b/shell/hush_test/hush-misc/func7.right
@@ -0,0 +1 @@
+Ok:0
diff --git a/shell/hush_test/hush-misc/func7.tests b/shell/hush_test/hush-misc/func7.tests
new file mode 100755
index 000000000..f5e03b6e1
--- /dev/null
+++ b/shell/hush_test/hush-misc/func7.tests
@@ -0,0 +1 @@
+if f() { echo Ok:$?; } then f; fi