From e26114c817b610424010cfbe91a743f591246ff1 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 28 Mar 2022 10:41:43 +0200
Subject: 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
---
 src/test/regress/sql/jsonpath.sql | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'src/test/regress/sql/jsonpath.sql')

diff --git a/src/test/regress/sql/jsonpath.sql b/src/test/regress/sql/jsonpath.sql
index 17ab7757831..d491714614a 100644
--- a/src/test/regress/sql/jsonpath.sql
+++ b/src/test/regress/sql/jsonpath.sql
@@ -163,8 +163,14 @@ select '0.0010'::jsonpath;
 select '0.0010e-1'::jsonpath;
 select '0.0010e+1'::jsonpath;
 select '0.0010e+2'::jsonpath;
+select '.001'::jsonpath;
+select '.001e1'::jsonpath;
+select '1.'::jsonpath;
+select '1.e1'::jsonpath;
+select '1a'::jsonpath;
 select '1e'::jsonpath;
 select '1.e'::jsonpath;
+select '1.2a'::jsonpath;
 select '1.2e'::jsonpath;
 select '1.2.e'::jsonpath;
 select '(1.2).e'::jsonpath;
@@ -173,9 +179,11 @@ select '1.e3'::jsonpath;
 select '1.e3.e'::jsonpath;
 select '1.e3.e4'::jsonpath;
 select '1.2e3'::jsonpath;
+select '1.2e3a'::jsonpath;
 select '1.2.e3'::jsonpath;
 select '(1.2).e3'::jsonpath;
 select '1..e'::jsonpath;
 select '1..e3'::jsonpath;
 select '(1.).e'::jsonpath;
 select '(1.).e3'::jsonpath;
+select '1?(2>3)'::jsonpath;
-- 
cgit v1.2.3

