aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonpath.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-03-28 10:41:43 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-03-28 11:11:39 +0200
commite26114c817b610424010cfbe91a743f591246ff1 (patch)
treedffb85fa7716419a907327af03ee3df09ce669e2 /src/backend/utils/adt/jsonpath.c
parent91c0570a791180aa3ff01d70eb16ed6c0d8283a3 (diff)
downloadpostgresql-e26114c817b610424010cfbe91a743f591246ff1.tar.gz
postgresql-e26114c817b610424010cfbe91a743f591246ff1.zip
Make JSON path numeric literals more correct
Per ECMAScript standard (ECMA-262, referenced by SQL standard), the syntax forms .1 1. should be allowed for decimal numeric literals, but the existing implementation rejected them. Also, by the same standard, reject trailing junk after numeric literals. Note that the ECMAScript standard for numeric literals is in respects like these slightly different from the JSON standard, which might be the original cause for this discrepancy. A change is that this kind of syntax is now rejected: 1.type() This needs to be written as (1).type() This is correct; normal JavaScript also does not accept this syntax. We also need to fix up the jsonpath output function for this case. We put parentheses around numeric items if they are followed by another path item. Reviewed-by: Nikita Glukhov <n.gluhov@postgrespro.ru> Discussion: https://www.postgresql.org/message-id/flat/50a828cc-0a00-7791-7883-2ed06dfb2dbb@enterprisedb.com
Diffstat (limited to 'src/backend/utils/adt/jsonpath.c')
-rw-r--r--src/backend/utils/adt/jsonpath.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/utils/adt/jsonpath.c b/src/backend/utils/adt/jsonpath.c
index 9be4e305ffa..91af0300952 100644
--- a/src/backend/utils/adt/jsonpath.c
+++ b/src/backend/utils/adt/jsonpath.c
@@ -500,9 +500,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
escape_json(buf, jspGetString(v, NULL));
break;
case jpiNumeric:
+ if (jspHasNext(v))
+ appendStringInfoChar(buf, '(');
appendStringInfoString(buf,
DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(jspGetNumeric(v)))));
+ if (jspHasNext(v))
+ appendStringInfoChar(buf, ')');
break;
case jpiBool:
if (jspGetBool(v))