Fix ${extract expansion for use within ${if inlist etc. Bug 1524
authorJeremy Harris <jgh146exb@wizmail.org>
Tue, 2 Sep 2014 22:37:57 +0000 (23:37 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Tue, 2 Sep 2014 22:53:28 +0000 (23:53 +0100)
The coding of the numeric test on the key decided that empty was numeric, and
insisted on a third substring even in syntax-check "skip" mode.  This failed
when a single expansion variable was used for the key (eg. $item) and the
defaults for string2, string3 were being assumed.  Skip the test in skip mode.

src/src/expand.c

index 8111c4212e6051cc8c1d801dd2de190b4d1534f2..a929e937c05c8fe5175406e481998675322cca03 100644 (file)
@@ -2752,6 +2752,8 @@ switch(cond_type)
       uschar *save_iterate_item = iterate_item;
       int (*compare)(const uschar *, const uschar *);
 
+      DEBUG(D_expand) debug_printf("condition: %s\n", name);
+
       tempcond = FALSE;
       if (cond_type == ECOND_INLISTI)
         compare = strcmpic;
@@ -2839,6 +2841,8 @@ switch(cond_type)
     int sep = 0;
     uschar *save_iterate_item = iterate_item;
 
+    DEBUG(D_expand) debug_printf("condition: %s\n", name);
+
     while (isspace(*s)) s++;
     if (*s++ != '{') goto COND_FAILED_CURLY_START;     /* }-for-text-editors */
     sub[0] = expand_string_internal(s, TRUE, &s, (yield == NULL), TRUE, resetok);
@@ -5229,25 +5233,28 @@ while (*s != 0)
             while (len > 0 && isspace(p[len-1])) len--;
             p[len] = 0;
 
-            if (*p == 0 && !skipping)
-              {
-              expand_string_message = US"first argument of \"extract\" must "
-                "not be empty";
-              goto EXPAND_FAILED;
-              }
+            if (!skipping)
+             {
+             if (*p == 0)
+               {
+               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;
+               }
+             }
             }
           }
         else goto EXPAND_FAILED_CURLY;