Expansions: fix forced-fail of extract. Bug 1815
authorJeremy Harris <jgh146exb@wizmail.org>
Thu, 14 Apr 2016 12:31:20 +0000 (13:31 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Thu, 14 Apr 2016 12:34:24 +0000 (13:34 +0100)
src/src/expand.c
test/scripts/0000-Basic/0002
test/stdout/0002

index 5189cdcfed5af230a5f80d60467f1271c1ec807c..2419161002e2865d8a111f8bfb6c5b7e80d41e08 100644 (file)
@@ -5359,7 +5359,7 @@ while (*s != 0)
     case EITEM_EXTRACT:
       {
       int i;
-      int j = 2;
+      int j;
       int field_number = 1;
       BOOL field_number_set = FALSE;
       uschar *save_lookup_value = lookup_value;
@@ -5369,12 +5369,12 @@ while (*s != 0)
 
       /* 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. */
+      Read a maximum of 5 arguments (inclding the yes/no) */
 
       if (skipping)
        {
         while (isspace(*s)) s++;
-        while (*s == '{')
+        for (j = 5; j > 0 && *s == '{'; j--)
          {
           if (!expand_string_internal(s+1, TRUE, &s, skipping, TRUE, &resetok))
            goto EXPAND_FAILED;                                 /*{*/
@@ -5385,6 +5385,13 @@ while (*s != 0)
            }
          while (isspace(*s)) s++;
          }
+       if (  Ustrncmp(s, "fail", 4) == 0
+          && (s[4] == '}' || s[4] == ' ' || s[4] == '\t' || !s[4])
+          )
+         {
+         s += 4;
+         while (isspace(*s)) s++;
+         }
        if (*s != '}')
          {
          expand_string_message = US"missing '}' closing extract";
@@ -5392,7 +5399,7 @@ while (*s != 0)
          }
        }
 
-      else for (i = 0; i < j; i++) /* Read the proper number of arguments */
+      else for (i = 0, j = 2; i < j; i++) /* Read the proper number of arguments */
         {
         while (isspace(*s)) s++;
         if (*s == '{')                                                 /*}*/
index bc61998ca6775440172a0302ee9c50d67e05e9c0..583adcff04f54a015e6dfcf23a0ddfa8154d510d 100644 (file)
@@ -617,6 +617,7 @@ ${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}}}}
+${map{a,1:b,2:c,3}{${extract{1}{,}{$item}{$value}fail}}}
 
 # Translation
 
index 13ef57a45813810768923f91f786bb1336d082b4..9a2768bdc99426e612a11487bdc83cfa0e883a14 100644 (file)
 > b
 > 
 > a:b:c
-> Failed: curly-bracket problem in conditional yes/no parsing: did not close with '}'
- remaining string is '{bogus_argument}}}}' inside "map" item
+> Failed: missing '}' closing extract inside "map" item
+> a:b:c
 > 
 > # Translation
 >