aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-12-19 20:23:47 -0600
committerRob Landley <rob@landley.net>2020-12-19 20:23:47 -0600
commitd7a2436cea81168078c7fdfc65114749abcbf9c6 (patch)
treea60b33f71544d5cf2ffefcc80f84eddc6f3d591f /toys
parent4b78acc7bc1af2e7e02bf07538c3f3a14c5e97ce (diff)
downloadtoybox-d7a2436cea81168078c7fdfc65114749abcbf9c6.tar.gz
Fix (( )) quote termination.
Diffstat (limited to 'toys')
-rw-r--r--toys/pending/sh.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/toys/pending/sh.c b/toys/pending/sh.c
index 4a96a939..218b8236 100644
--- a/toys/pending/sh.c
+++ b/toys/pending/sh.c
@@ -513,11 +513,13 @@ static char *parse_word(char *start, int early, int quote)
// Things we should only return at the _start_ of a word
- if (strstart(&end, "<(") || strstart(&end, ">(")) toybuf[quote++]=')';
-
// Redirections. 123<<file- parses as 2 args: "123<<" "file-".
s = end + redir_prefix(end);
if ((i = anystart(s, (void *)redirectors))) return s+i;
+ if (strstart(&s, "<(") || strstart(&s, ">(")) {
+ toybuf[quote++]=')';
+ end = s;
+ }
// (( is a special quote at the start of a word
if (strstart(&end, "((")) toybuf[quote++] = 254;
@@ -534,14 +536,13 @@ static char *parse_word(char *start, int early, int quote)
// Handle quote contexts
if ((q = quote ? toybuf[quote-1] : 0)) {
-
// when waiting for parentheses, they nest
if ((q == ')' || q >= 254) && (*end == '(' || *end == ')')) {
if (*end == '(') qc++;
else if (qc) qc--;
else if (q >= 254) {
// (( can end with )) or retroactively become two (( if we hit one )
- if (strstart(&end, "))")) quote--;
+ if (*end == ')' && end[1] == ')') quote--, end++;
else if (q == 254) return start+1;
else if (q == 255) toybuf[quote-1] = ')';
} else if (*end == ')') quote--;
@@ -561,7 +562,6 @@ static char *parse_word(char *start, int early, int quote)
// Things that only matter when unquoted
if (isspace(*end)) break;
- if (*end == ')') return end+(start==end);
// Flow control characters that end pipeline segments
s = end + anystart(end, (char *[]){";;&", ";;", ";&", ";", "||",