Commit | Line | Data |
---|---|---|
01e60269 AM |
1 | From b2734f7b45111f9b7de790c7b334a2ece47675b5 Mon Sep 17 00:00:00 2001 |
2 | From: Jeremy Harris <jgh146exb@wizmail.org> | |
3 | Date: Sat, 9 Feb 2019 16:56:59 +0000 | |
4 | Subject: [PATCH 1/7] Fix json extract operator for unfound case | |
5 | ||
6 | (cherry picked from commit e73798976812e652320f096870359ef35ed069ff) | |
7 | --- | |
8 | doc/doc-docbook/spec.xfpt | 4 ++++ | |
9 | src/expand.c | 13 ++++++++----- | |
10 | test/scripts/0000-Basic/0002 | 3 +++ | |
11 | test/stdout/0002 | 3 +++ | |
12 | 4 files changed, 18 insertions(+), 5 deletions(-) | |
13 | ||
14 | --- a/src/expand.c | |
15 | +++ b/src/expand.c | |
16 | @@ -3901,7 +3901,8 @@ return NULL; | |
17 | /* Pull off the leading array or object element, returning | |
18 | a copy in an allocated string. Update the list pointer. | |
19 | ||
20 | -The element may itself be an abject or array. | |
21 | +The element may itself be an object or array. | |
22 | +Return NULL when the list is empty. | |
23 | */ | |
24 | ||
25 | uschar * | |
26 | @@ -3923,6 +3924,7 @@ for (item = s; | |
27 | case '}': object_depth--; break; | |
28 | } | |
29 | *list = *s ? s+1 : s; | |
30 | +if (item == s) return NULL; | |
31 | item = string_copyn(item, s - item); | |
32 | DEBUG(D_expand) debug_printf_indent(" json ele: '%s'\n", item); | |
33 | return US item; | |
34 | @@ -5790,10 +5792,11 @@ while (*s != 0) | |
35 | } | |
36 | while (field_number > 0 && (item = json_nextinlist(&list))) | |
37 | field_number--; | |
38 | - s = item; | |
39 | - lookup_value = s; | |
40 | - while (*s) s++; | |
41 | - while (--s >= lookup_value && isspace(*s)) *s = '\0'; | |
42 | + if ((lookup_value = s = item)) | |
43 | + { | |
44 | + while (*s) s++; | |
45 | + while (--s >= lookup_value && isspace(*s)) *s = '\0'; | |
46 | + } | |
47 | } | |
48 | else | |
49 | { | |
50 | --- a/doc/spec.txt | |
51 | +++ b/doc/spec.txt | |
52 | @@ -8776,6 +8776,8 @@ ${extract json{<key>}{<string1>}{<string | |
53 | The braces, commas and colons, and the quoting of the member name are | |
54 | required; the spaces are optional. Matching of the key against the member | |
55 | names is done case-sensitively. | |
56 | + If a returned value is a JSON string, it retains its leading and | |
57 | + trailing quotes. | |
58 | ||
59 | The results of matching are handled as above. | |
60 | ||
61 | @@ -8813,6 +8815,8 @@ ${extract json{<number>}}{<string1>}{<st | |
62 | ||
63 | Field selection and result handling is as above; there is no choice of | |
64 | field separator. | |
65 | + If a returned value is a JSON string, it retains its leading and | |
66 | + trailing quotes. | |
67 | ||
68 | ${filter{<string>}{<condition>}} | |
69 |