aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2014-09-09 08:52:06 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-12-17 15:24:37 +0200
commit6b41f7cb1fb39932b53551715b35823a0c8af4f1 (patch)
treed4175a8c0ffe08ef639dad1366863d5a46d6747c /src
parentfe9bc685c39e79c892bf234163e7fed903c1362d (diff)
downloadgrecs-6b41f7cb1fb39932b53551715b35823a0c8af4f1.tar.gz
grecs-6b41f7cb1fb39932b53551715b35823a0c8af4f1.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/wordsplit.c16
1 files changed, 11 insertions, 5 deletions
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++;

Return to:

Send suggestions and report system problems to the System administrator.