From 76db5adbf70046dec92309a9785da08d1acf4e9d Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Thu, 12 Jun 2008 12:58:20 +0000 Subject: [PATCH] hush: fix for nested $()s with escapes + testsuite --- shell/hush.c | 12 +++++++++++- shell/hush_test/hush-psubst/tick3.tests | 1 - shell/hush_test/hush-psubst/tick4.right | 7 +++++++ shell/hush_test/hush-psubst/tick4.tests | 7 +++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 shell/hush_test/hush-psubst/tick4.right create mode 100755 shell/hush_test/hush-psubst/tick4.tests diff --git a/shell/hush.c b/shell/hush.c index 735526a1d..77a305191 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -3498,6 +3498,13 @@ static void add_till_closing_curly_brace(o_string *dest, struct in_str *input) o_addqchr(dest, ch, 1); continue; } + if (ch == '\\') { /* \x. Copy verbatim. Important for \(, \) */ + ch = i_getch(input); + if (ch == EOF) + break; + o_addqchr(dest, ch, 1); + continue; + } } } #endif /* ENABLE_HUSH_TICK */ @@ -3556,13 +3563,16 @@ static int handle_dollar(o_string *dest, struct in_str *input) o_addchr(dest, SPECIAL_VAR_SYMBOL); break; #if ENABLE_HUSH_TICK - case '(': + case '(': { + //int pos = dest->length; i_getch(input); o_addchr(dest, SPECIAL_VAR_SYMBOL); o_addchr(dest, quote_mask | '`'); add_till_closing_curly_brace(dest, input); + //bb_error_msg("RES '%s'", dest->data + pos); o_addchr(dest, SPECIAL_VAR_SYMBOL); break; + } #endif case '-': case '_': diff --git a/shell/hush_test/hush-psubst/tick3.tests b/shell/hush_test/hush-psubst/tick3.tests index 97b45e4b4..2b055bb69 100755 --- a/shell/hush_test/hush-psubst/tick3.tests +++ b/shell/hush_test/hush-psubst/tick3.tests @@ -1,4 +1,3 @@ -#!/bin/sh TEST=Q # \` is special echo `echo '\'TEST\`echo ZZ\`BEST` diff --git a/shell/hush_test/hush-psubst/tick4.right b/shell/hush_test/hush-psubst/tick4.right new file mode 100644 index 000000000..d8030eafd --- /dev/null +++ b/shell/hush_test/hush-psubst/tick4.right @@ -0,0 +1,7 @@ +(TEST) BEST +TEST) BEST +((TEST) BEST +) +abc +a)c +OK: 0 diff --git a/shell/hush_test/hush-psubst/tick4.tests b/shell/hush_test/hush-psubst/tick4.tests new file mode 100755 index 000000000..f2305fb3d --- /dev/null +++ b/shell/hush_test/hush-psubst/tick4.tests @@ -0,0 +1,7 @@ +echo $(echo '(TEST)' BEST) +echo $(echo 'TEST)' BEST) +echo $(echo \(\(TEST\) BEST) +echo $(echo \)) +echo $(echo a"`echo "b"`"c ) +echo $(echo a"`echo ")"`"c ) +echo OK: $? -- 2.25.1