From 6b41f7cb1fb39932b53551715b35823a0c8af4f1 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 9 Sep 2014 08:52:06 +0300 Subject: wordsplit: Fix expansion of ${...} * src/wordsplit.c (expvar): Ensure value is set. Pass WRDSF_QUOTE to wordsplit (scan_word): Treat ${...} as a single word. * tests/wordsplit.at: Add more tests. * tests/wsp.c: Fix error message. --- src/wordsplit.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/wordsplit.c b/src/wordsplit.c index dbb5aa5..4605e2e 100644 --- a/src/wordsplit.c +++ b/src/wordsplit.c @@ -612,8 +612,7 @@ node_split_prefix (struct wordsplit *wsp, static int find_closing_cbrace (const char *str, size_t i, size_t len, size_t * poff) { - enum - { st_init, st_squote, st_dquote } state = st_init; + enum { st_init, st_squote, st_dquote } state = st_init; size_t level = 1; for (; i < len; i++) @@ -779,7 +778,9 @@ expvar (struct wordsplit *wsp, const char *str, size_t len, } else if (wsp->ws_flags & WRDSF_GETVAR) value = wsp->ws_getvar (str, i, wsp->ws_closure); - + else + value = NULL; + if (!value) { if (defstr) @@ -866,7 +867,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len, ws.ws_delim = wsp->ws_delim; rc = wordsplit (value, &ws, - WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_DELIM | WRDSF_WS); + WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_DELIM | + WRDSF_WS | WRDSF_QUOTE); free (value); if (rc) { @@ -1192,7 +1194,11 @@ scan_word (struct wordsplit *wsp, size_t start) } } - if (ISDELIM (wsp, command[i])) + if (!(wsp->ws_flags & WRDSF_NOVAR) + && command[i] == '$' && command[i+1] == '{' + && find_closing_cbrace (command, i + 2, len, &i) == 0) + continue; + else if (ISDELIM (wsp, command[i])) break; else i++; -- cgit v1.2.1