From d7a2436cea81168078c7fdfc65114749abcbf9c6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 19 Dec 2020 20:23:47 -0600 Subject: Fix (( )) quote termination. --- toys/pending/sh.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'toys/pending') 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<(")) { + 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 *[]){";;&", ";;", ";&", ";", "||", -- cgit v1.2.3