[exim-cvs] Expansions: fix json extract for de-wrapping nest…

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] Expansions: fix json extract for de-wrapping nested objects. Bug 2322
Gitweb: https://git.exim.org/exim.git/commitdiff/9d03af0a7d6bfcc13156ce8fd676ce00dd32d228
Commit:     9d03af0a7d6bfcc13156ce8fd676ce00dd32d228
Parent:     8fdf20fd84ec88d8f8a250f56d2b4d29ba946392
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sun Sep 30 21:42:40 2018 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sun Sep 30 21:42:40 2018 +0100


    Expansions: fix json extract for de-wrapping nested objects.  Bug 2322
---
 src/src/expand.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)


diff --git a/src/src/expand.c b/src/src/expand.c
index 43f572e..4a88b44 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -3869,6 +3869,8 @@ static uschar *
dewrap(uschar * s, const uschar * wrap)
{
uschar * p = s;
+unsigned depth = 0;
+BOOL quotesmode = wrap[0] == wrap[1];

while (isspace(*p)) p++;

@@ -3879,11 +3881,15 @@ if (*p == *wrap)
   while (*p)
     {
     if (*p == '\\') p++;
+    else if (!quotesmode && *p == wrap[-1]) depth++;
     else if (*p == *wrap)
-      {
-      *p = '\0';
-      return s;
-      }
+      if (depth == 0)
+    {
+    *p = '\0';
+    return s;
+    }
+      else
+    depth--;
     p++;
     }
   }
@@ -3917,7 +3923,9 @@ for (item = s;
     case '}': object_depth--; break;
     }
 *list = *s ? s+1 : s;
-return string_copyn(item, s - item);
+item = string_copyn(item, s - item);
+DEBUG(D_expand) debug_printf_indent("  json ele: '%s'\n", item);
+return US item;
 }