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.
for the new environment-manipulation done at startup. Move the routines
from being local to tls.c to being global via the os.c file.
for the new environment-manipulation done at startup. Move the routines
from being local to tls.c to being global via the os.c file.
+JH/48 Bug 1807: Fix ${extract } for the numeric/3-string case. While preparsing
+ an extract embedded as result-arg for a map, the first arg for extract
+ is unavailable so we cannot tell if this is a numbered or keyed
+ extraction. Accept either.
+
int save_expand_nmax =
save_expand_strings(save_expand_nstring, save_expand_nlength);
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 == '{') /*}*/
{
while (isspace(*s)) s++;
if (*s == '{') /*}*/
while (len > 0 && isspace(p[len-1])) len--;
p[len] = 0;
while (len > 0 && isspace(p[len-1])) len--;
p[len] = 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;
${extract{ }{X=3}}
${extract{ 2 }{ }{a b c}}
${extract{ }{X=3}}
${extract{ 2 }{ }{a b c}}
+${map{a,1:b,2:c,3}{${extract{1}{,}{$item}{$value}{}}}}
+${map{a,1:b,2:c,3}{${extract{1}{,}{$item}{$value}{failcase}{bogus_argument}}}}
+
# Translation
abcdea aaa xyz ${tr{abcdea}{aaa}{xyz}}
# Translation
abcdea aaa xyz ${tr{abcdea}{aaa}{xyz}}
> Failed: first argument of "extract" must not be empty
> b
>
> Failed: first argument of "extract" must not be empty
> b
>
+> a:b:c
+> Failed: missing or misplaced { or } inside "map" item
+>
> # Translation
>
> abcdea aaa xyz zbcdez
> # Translation
>
> abcdea aaa xyz zbcdez