From: Jeremy Harris Date: Sat, 9 Feb 2019 16:56:59 +0000 (+0000) Subject: Fix json extract operator for unfound case X-Git-Url: https://git.exim.org/exim.git/commitdiff_plain/f07c22772581c167112540af35b997e6829eef64 Fix json extract operator for unfound case (cherry picked from commit e73798976812e652320f096870359ef35ed069ff) (cherry picked from commit b2734f7b45111f9b7de790c7b334a2ece47675b5) (cherry picked from commit b88b6f6f3a29b70cd0b314da8ceab18b0b34eed6) --- diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 4d4bab7c2..20b08f693 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -9537,6 +9537,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. +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. @@ -9584,6 +9586,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. +If a returned value is a JSON string, it retains its leading and +trailing quotes. .wen diff --git a/src/src/expand.c b/src/src/expand.c index 1bcfbe8d9..c2eba072a 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -5861,10 +5861,11 @@ while (*s != 0) } while (field_number > 0 && (item = json_nextinlist(&list))) field_number--; - s = item; - lookup_value = s; - while (*s) s++; - while (--s >= lookup_value && isspace(*s)) *s = '\0'; + if ((lookup_value = s = item)) + { + while (*s) s++; + while (--s >= lookup_value && isspace(*s)) *s = '\0'; + } } else { diff --git a/test/scripts/0000-Basic/0002 b/test/scripts/0000-Basic/0002 index e192a5593..7a9b38dba 100644 --- a/test/scripts/0000-Basic/0002 +++ b/test/scripts/0000-Basic/0002 @@ -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{nonexistent}{ \{"id": \{"a":101, "b":102\}, "IDs": \{"1":116, "2":943, "3":234\}\} }}> +expect: <> + **** # Test "escape" with print_topbitchars exim -be -DPTBC=print_topbitchars diff --git a/test/stdout/0002 b/test/stdout/0002 index 949c35eb2..c2f5f2f3c 100644 --- a/test/stdout/0002 +++ b/test/stdout/0002 @@ -845,6 +845,9 @@ xyz > {"1":116, "2":943, "3":234} > expect: {"1":116, "2":943, "3":234} > +> <> +> expect: <> +> > > escape: B7·F2ò >