Fix json extract operator for unfound case
authorJeremy Harris <jgh146exb@wizmail.org>
Thu, 10 Jan 2019 13:05:10 +0000 (13:05 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Thu, 10 Jan 2019 15:24:00 +0000 (15:24 +0000)
doc/doc-docbook/spec.xfpt
src/src/expand.c
test/scripts/0000-Basic/0002
test/stdout/0002

index a164835033c887cb0a78240eb8fc08e50ef81e03..7d4dfbbe70797b752f5acc0da899cf77254a09dc 100644 (file)
@@ -6628,9 +6628,10 @@ of the JSON structure.
 If a selector is numeric, it must apply to a JSON array; the (zero-based)
 nunbered array element is selected.
 Otherwise it must apply to a JSON object; the named element is selected.
 If a selector is numeric, it must apply to a JSON array; the (zero-based)
 nunbered array element is selected.
 Otherwise it must apply to a JSON object; the named element is selected.
-The final resulting object can be a simple JSOM type or a JSON object
+The final resulting element can be a simple JSON type or a JSON object
 or array; for the latter two a string-representation os the JSON
 is returned.
 or array; for the latter two a string-representation os the JSON
 is returned.
+For elements of type string, the returned value is de-quoted.
 .wen
 .next
 .cindex "linear search"
 .wen
 .next
 .cindex "linear search"
@@ -9424,6 +9425,8 @@ The expanded <&'string1'&> must be of the form:
 The braces, commas and colons, and the quoting of the member name are required;
 the spaces are optional.
 Matching of the key against the member names is done case-sensitively.
 The braces, commas and colons, and the quoting of the member name are required;
 the spaces are optional.
 Matching of the key against the member names is done case-sensitively.
+If a returned value is a JSON string, it retains its leading and
+trailing quotes.
 . XXX should be a UTF-8 compare
 
 The results of matching are handled as above.
 . XXX should be a UTF-8 compare
 
 The results of matching are handled as above.
@@ -9471,6 +9474,8 @@ apart from leading and trailing white space, which is ignored.
 
 Field selection and result handling is as above;
 there is no choice of field separator.
 
 Field selection and result handling is as above;
 there is no choice of field separator.
+If a returned value is a JSON string, it retains its leading and
+trailing quotes.
 .wen
 
 
 .wen
 
 
index d6fd8488a8b1f673ac7b45f1371d9f44e38a1555..2f05737fc4c7f89e2d6b8c5c0620ff71ba88dfcb 100644 (file)
@@ -3894,6 +3894,7 @@ return NULL;
 a copy in an allocated string.  Update the list pointer.
 
 The element may itself be an abject or array.
 a copy in an allocated string.  Update the list pointer.
 
 The element may itself be an abject or array.
+Return NULL when the list is empty.
 */
 
 uschar *
 */
 
 uschar *
@@ -3915,6 +3916,7 @@ for (item = s;
     case '}': object_depth--; break;
     }
 *list = *s ? s+1 : s;
     case '}': object_depth--; break;
     }
 *list = *s ? s+1 : s;
+if (item == s) return NULL;
 item = string_copyn(item, s - item);
 DEBUG(D_expand) debug_printf_indent("  json ele: '%s'\n", item);
 return US item;
 item = string_copyn(item, s - item);
 DEBUG(D_expand) debug_printf_indent("  json ele: '%s'\n", item);
 return US item;
index e192a5593fd8465b364c72df10529f09c795f107..7a9b38dba3ab1d2df5e602008876870d57598e16 100644 (file)
@@ -902,6 +902,9 @@ expect: {"1":116, "2":943, "3":234}
 ${extract json{IDs}{ \{"id": \{"a":101, "b":102\}, "IDs": \{"1":116, "2":943, "3":234\}\} }}
 expect: {"1":116, "2":943, "3":234}
 
 ${extract json{IDs}{ \{"id": \{"a":101, "b":102\}, "IDs": \{"1":116, "2":943, "3":234\}\} }}
 expect: {"1":116, "2":943, "3":234}
 
+<${extract json{nonexistent}{ \{"id": \{"a":101, "b":102\}, "IDs": \{"1":116, "2":943, "3":234\}\} }}>
+expect: <>
+
 ****
 # Test "escape" with print_topbitchars
 exim -be -DPTBC=print_topbitchars
 ****
 # Test "escape" with print_topbitchars
 exim -be -DPTBC=print_topbitchars
index 949c35eb247451f53378f94056ab7118723019df..44117a9fc50c3f2937c1668407b24e99a25bee14 100644 (file)
@@ -845,6 +845,9 @@ xyz
 > {"1":116, "2":943, "3":234}
 > expect: {"1":116, "2":943, "3":234}
 > 
 > {"1":116, "2":943, "3":234}
 > expect: {"1":116, "2":943, "3":234}
 > 
+> Failed: missing '"' wrapping string key for extract json
+> expect: <>
+> 
 > 
 > escape: B7·F2ò
 > 
 > 
 > escape: B7·F2ò
 >