Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2e64350

Browse files
committed
Restrict some cases in parsing numerics in jsonpath
Jsonpath now accepts integers with leading zeroes and floats starting with a dot. However, SQL standard requires to follow JSON specification, which doesn't allow none of these cases. Our json[b] datatypes also restrict that. So, restrict it in jsonpath altogether. Author: Nikita Glukhov
1 parent 0a02e2a commit 2e64350

File tree

2 files changed

+55
-68
lines changed

2 files changed

+55
-68
lines changed

src/backend/utils/adt/jsonpath_scan.l

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ any [^\?\%\$\.\[\]\{\}\(\)\|\&\!\=\<\>\@\#\,\*:\-\+\/\\\"\' \t\n\r\f]
8080
blank [ \t\n\r\f]
8181

8282
digit [0-9]
83-
integer {digit}+
84-
decimal {digit}*\.{digit}+
85-
decimalfail {digit}+\.
83+
integer (0|[1-9]{digit}*)
84+
decimal {integer}\.{digit}+
85+
decimalfail {integer}\.
8686
real ({integer}|{decimal})[Ee][-+]?{digit}+
8787
realfail1 ({integer}|{decimal})[Ee]
8888
realfail2 ({integer}|{decimal})[Ee][-+]

src/test/regress/expected/jsonpath.out

+52-65
Original file line numberDiff line numberDiff line change
@@ -547,23 +547,20 @@ select '$ ? (@.a < +1)'::jsonpath;
547547
(1 row)
548548

549549
select '$ ? (@.a < .1)'::jsonpath;
550-
jsonpath
551-
-----------------
552-
$?(@."a" < 0.1)
553-
(1 row)
554-
550+
ERROR: bad jsonpath representation
551+
LINE 1: select '$ ? (@.a < .1)'::jsonpath;
552+
^
553+
DETAIL: syntax error, unexpected '.' at or near "."
555554
select '$ ? (@.a < -.1)'::jsonpath;
556-
jsonpath
557-
------------------
558-
$?(@."a" < -0.1)
559-
(1 row)
560-
555+
ERROR: bad jsonpath representation
556+
LINE 1: select '$ ? (@.a < -.1)'::jsonpath;
557+
^
558+
DETAIL: syntax error, unexpected '.' at or near "."
561559
select '$ ? (@.a < +.1)'::jsonpath;
562-
jsonpath
563-
-----------------
564-
$?(@."a" < 0.1)
565-
(1 row)
566-
560+
ERROR: bad jsonpath representation
561+
LINE 1: select '$ ? (@.a < +.1)'::jsonpath;
562+
^
563+
DETAIL: syntax error, unexpected '.' at or near "."
567564
select '$ ? (@.a < 0.1)'::jsonpath;
568565
jsonpath
569566
-----------------
@@ -619,23 +616,20 @@ select '$ ? (@.a < +1e1)'::jsonpath;
619616
(1 row)
620617

621618
select '$ ? (@.a < .1e1)'::jsonpath;
622-
jsonpath
623-
---------------
624-
$?(@."a" < 1)
625-
(1 row)
626-
619+
ERROR: bad jsonpath representation
620+
LINE 1: select '$ ? (@.a < .1e1)'::jsonpath;
621+
^
622+
DETAIL: syntax error, unexpected '.' at or near "."
627623
select '$ ? (@.a < -.1e1)'::jsonpath;
628-
jsonpath
629-
----------------
630-
$?(@."a" < -1)
631-
(1 row)
632-
624+
ERROR: bad jsonpath representation
625+
LINE 1: select '$ ? (@.a < -.1e1)'::jsonpath;
626+
^
627+
DETAIL: syntax error, unexpected '.' at or near "."
633628
select '$ ? (@.a < +.1e1)'::jsonpath;
634-
jsonpath
635-
---------------
636-
$?(@."a" < 1)
637-
(1 row)
638-
629+
ERROR: bad jsonpath representation
630+
LINE 1: select '$ ? (@.a < +.1e1)'::jsonpath;
631+
^
632+
DETAIL: syntax error, unexpected '.' at or near "."
639633
select '$ ? (@.a < 0.1e1)'::jsonpath;
640634
jsonpath
641635
---------------
@@ -691,23 +685,20 @@ select '$ ? (@.a < +1e-1)'::jsonpath;
691685
(1 row)
692686

693687
select '$ ? (@.a < .1e-1)'::jsonpath;
694-
jsonpath
695-
------------------
696-
$?(@."a" < 0.01)
697-
(1 row)
698-
688+
ERROR: bad jsonpath representation
689+
LINE 1: select '$ ? (@.a < .1e-1)'::jsonpath;
690+
^
691+
DETAIL: syntax error, unexpected '.' at or near "."
699692
select '$ ? (@.a < -.1e-1)'::jsonpath;
700-
jsonpath
701-
-------------------
702-
$?(@."a" < -0.01)
703-
(1 row)
704-
693+
ERROR: bad jsonpath representation
694+
LINE 1: select '$ ? (@.a < -.1e-1)'::jsonpath;
695+
^
696+
DETAIL: syntax error, unexpected '.' at or near "."
705697
select '$ ? (@.a < +.1e-1)'::jsonpath;
706-
jsonpath
707-
------------------
708-
$?(@."a" < 0.01)
709-
(1 row)
710-
698+
ERROR: bad jsonpath representation
699+
LINE 1: select '$ ? (@.a < +.1e-1)'::jsonpath;
700+
^
701+
DETAIL: syntax error, unexpected '.' at or near "."
711702
select '$ ? (@.a < 0.1e-1)'::jsonpath;
712703
jsonpath
713704
------------------
@@ -763,23 +754,20 @@ select '$ ? (@.a < +1e+1)'::jsonpath;
763754
(1 row)
764755

765756
select '$ ? (@.a < .1e+1)'::jsonpath;
766-
jsonpath
767-
---------------
768-
$?(@."a" < 1)
769-
(1 row)
770-
757+
ERROR: bad jsonpath representation
758+
LINE 1: select '$ ? (@.a < .1e+1)'::jsonpath;
759+
^
760+
DETAIL: syntax error, unexpected '.' at or near "."
771761
select '$ ? (@.a < -.1e+1)'::jsonpath;
772-
jsonpath
773-
----------------
774-
$?(@."a" < -1)
775-
(1 row)
776-
762+
ERROR: bad jsonpath representation
763+
LINE 1: select '$ ? (@.a < -.1e+1)'::jsonpath;
764+
^
765+
DETAIL: syntax error, unexpected '.' at or near "."
777766
select '$ ? (@.a < +.1e+1)'::jsonpath;
778-
jsonpath
779-
---------------
780-
$?(@."a" < 1)
781-
(1 row)
782-
767+
ERROR: bad jsonpath representation
768+
LINE 1: select '$ ? (@.a < +.1e+1)'::jsonpath;
769+
^
770+
DETAIL: syntax error, unexpected '.' at or near "."
783771
select '$ ? (@.a < 0.1e+1)'::jsonpath;
784772
jsonpath
785773
---------------
@@ -823,11 +811,10 @@ select '0'::jsonpath;
823811
(1 row)
824812

825813
select '00'::jsonpath;
826-
jsonpath
827-
----------
828-
0
829-
(1 row)
830-
814+
ERROR: bad jsonpath representation
815+
LINE 1: select '00'::jsonpath;
816+
^
817+
DETAIL: syntax error, unexpected IDENT_P at end of input
831818
select '0.0'::jsonpath;
832819
jsonpath
833820
----------

0 commit comments

Comments
 (0)