summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2016-03-09 17:40:48 +0000
committerJeremy Harris <jgh146exb@wizmail.org>2016-03-09 18:45:31 +0000
commit93cc2d6e053031a7008f73ca1ea072038bfa3fc8 (patch)
tree76d079a8d6bd231559ddd84131e663e975946d5b /src
parentfae3a611be53dbf58cbb7c2c4846081ecb87606e (diff)
String expansions: fix ${extract }, for the numeric/3-string case. Bug 1807
Broken-by: 82dbd37 In "skipping" mode when parsing an expansion we want to avoid expanding the arguments, as the data for expansion is not necessarily valid. This bit us previously for an extract within an "if inlist". But the number of args for ${extract } depends on the expanded value of the first arg. Retreat from strict parsing and just line up the outer braces, accepting any number of args while skipping. The separate non-skipping execution will do the proper checking.
Diffstat (limited to 'src')
-rw-r--r--src/src/expand.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/src/expand.c b/src/src/expand.c
index 99d2ffc00..47f1453be 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -5307,9 +5307,25 @@ while (*s != 0)
int save_expand_nmax =
save_expand_strings(save_expand_nstring, save_expand_nlength);
- /* Read the arguments */
+ /* While skipping we cannot rely on the data for expansions being
+ available (eg. $item) hence cannot decide on numeric vs. keyed.
+ Just read as many arguments as there are. */
- for (i = 0; i < j; i++)
+ if (skipping)
+ {
+ while (isspace(*s)) s++;
+ while (*s == '{')
+ {
+ if (!expand_string_internal(s+1, TRUE, &s, skipping, TRUE, &resetok))
+ goto EXPAND_FAILED; /*{*/
+ if (*s++ != '}') goto EXPAND_FAILED_CURLY;
+ while (isspace(*s)) s++;
+ }
+ if (*s != '}')
+ goto EXPAND_FAILED_CURLY;
+ }
+
+ else for (i = 0; i < j; i++) /* Read the proper number of arguments */
{
while (isspace(*s)) s++;
if (*s == '{') /*}*/
@@ -5336,27 +5352,24 @@ while (*s != 0)
while (len > 0 && isspace(p[len-1])) len--;
p[len] = 0;
- if (!skipping)
+ if (*p == 0)
{
- if (*p == 0)
- {
- expand_string_message = US"first argument of \"extract\" must "
- "not be empty";
- goto EXPAND_FAILED;
- }
+ expand_string_message = US"first argument of \"extract\" must "
+ "not be empty";
+ goto EXPAND_FAILED;
+ }
- if (*p == '-')
- {
- field_number = -1;
- p++;
- }
- while (*p != 0 && isdigit(*p)) x = x * 10 + *p++ - '0';
- if (*p == 0)
- {
- field_number *= x;
- j = 3; /* Need 3 args */
- field_number_set = TRUE;
- }
+ if (*p == '-')
+ {
+ field_number = -1;
+ p++;
+ }
+ while (*p != 0 && isdigit(*p)) x = x * 10 + *p++ - '0';
+ if (*p == 0)
+ {
+ field_number *= x;
+ j = 3; /* Need 3 args */
+ field_number_set = TRUE;
}
}
}