Skip to content

Commit 6044180

Browse files
committed
\u* now works as expected, improve parse rules for \
1 parent aed521c commit 6044180

File tree

3 files changed

+130
-10
lines changed

3 files changed

+130
-10
lines changed

expected/jsquery.out

+97
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,103 @@ select 'a\r = "\n\""'::jsquery;
861861
"a\r" = "\n\""
862862
(1 row)
863863

864+
select 'a\r = "\u0000"'::jsquery;
865+
jsquery
866+
------------------
867+
"a\r" = "\u0000"
868+
(1 row)
869+
870+
select 'a\r = \u0000'::jsquery;
871+
jsquery
872+
------------------
873+
"a\r" = "\u0000"
874+
(1 row)
875+
876+
select 'a\r = "\abcd"'::jsquery AS err;
877+
ERROR: bad jsquery representation
878+
LINE 1: select 'a\r = "\abcd"'::jsquery AS err;
879+
^
880+
DETAIL: Escape sequence is invalid at or near "\a"
881+
select 'a\r = "\\abcd"'::jsquery;
882+
jsquery
883+
------------------
884+
"a\r" = "\\abcd"
885+
(1 row)
886+
887+
select 'a\r = "x\u0000"'::jsquery;
888+
jsquery
889+
-------------------
890+
"a\r" = "x\u0000"
891+
(1 row)
892+
893+
select 'a\r = x\u0000'::jsquery;
894+
jsquery
895+
-------------------
896+
"a\r" = "x\u0000"
897+
(1 row)
898+
899+
select 'a\r = "x\abcd"'::jsquery AS err;
900+
ERROR: bad jsquery representation
901+
LINE 1: select 'a\r = "x\abcd"'::jsquery AS err;
902+
^
903+
DETAIL: Escape sequence is invalid at or near "\a"
904+
select 'a\r = "x\\abcd"'::jsquery;
905+
jsquery
906+
-------------------
907+
"a\r" = "x\\abcd"
908+
(1 row)
909+
910+
select 'a\r = "x\u0000x"'::jsquery;
911+
jsquery
912+
--------------------
913+
"a\r" = "x\u0000x"
914+
(1 row)
915+
916+
select 'a\r = x\u0000x'::jsquery;
917+
jsquery
918+
--------------------
919+
"a\r" = "x\u0000x"
920+
(1 row)
921+
922+
select 'a\r = "x\abcdx"'::jsquery AS err;
923+
ERROR: bad jsquery representation
924+
LINE 1: select 'a\r = "x\abcdx"'::jsquery AS err;
925+
^
926+
DETAIL: Escape sequence is invalid at or near "\a"
927+
select 'a\r = "x\\abcdx"'::jsquery;
928+
jsquery
929+
--------------------
930+
"a\r" = "x\\abcdx"
931+
(1 row)
932+
933+
select 'a\r = "\u0000x"'::jsquery;
934+
jsquery
935+
-------------------
936+
"a\r" = "\u0000x"
937+
(1 row)
938+
939+
select 'a\r = \u0000x'::jsquery;
940+
jsquery
941+
-------------------
942+
"a\r" = "\u0000x"
943+
(1 row)
944+
945+
select 'a\r = "\abcdx"'::jsquery AS err;
946+
ERROR: bad jsquery representation
947+
LINE 1: select 'a\r = "\abcdx"'::jsquery AS err;
948+
^
949+
DETAIL: Escape sequence is invalid at or near "\a"
950+
select 'a\r = "\\abcdx"'::jsquery;
951+
jsquery
952+
-------------------
953+
"a\r" = "\\abcdx"
954+
(1 row)
955+
956+
select 'a\r = x"\\abcd"'::jsquery AS err;
957+
ERROR: bad jsquery representation
958+
LINE 1: select 'a\r = x"\\abcd"'::jsquery AS err;
959+
^
960+
DETAIL: syntax error, unexpected STRING_P, expecting $end at or near """
864961
---table and index
865962
select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0;
866963
count

jsquery_scan.l

+16-10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ unicode \\u[0-9A-Fa-f]{4}
9696
BEGIN xQUOTED;
9797
}
9898
99+
<INITIAL>\\ {
100+
yyless(0);
101+
addstring(true, "", 0);
102+
BEGIN xNONQUOTED;
103+
}
104+
99105
<xNONQUOTED>{any}+ {
100106
addstring(false, yytext, yyleng);
101107
}
@@ -120,27 +126,27 @@ unicode \\u[0-9A-Fa-f]{4}
120126
return checkSpecialVal();
121127
}
122128
123-
<INITIAL,xNONQUOTED,xQUOTED>\\[\"\\\/] {
129+
<xNONQUOTED,xQUOTED>\\[\"\\\/] {
124130
addchar(false, yytext[1]);
125131
}
126132
127-
<INITIAL,xNONQUOTED,xQUOTED>\\b { addchar(false, '\b'); }
133+
<xNONQUOTED,xQUOTED>\\b { addchar(false, '\b'); }
128134
129-
<INITIAL,xNONQUOTED,xQUOTED>\\f { addchar(false, '\f'); }
135+
<xNONQUOTED,xQUOTED>\\f { addchar(false, '\f'); }
130136
131-
<INITIAL,xNONQUOTED,xQUOTED>\\n { addchar(false, '\n'); }
137+
<xNONQUOTED,xQUOTED>\\n { addchar(false, '\n'); }
132138
133-
<INITIAL,xNONQUOTED,xQUOTED>\\r { addchar(false, '\r'); }
139+
<xNONQUOTED,xQUOTED>\\r { addchar(false, '\r'); }
134140
135-
<INITIAL,xNONQUOTED,xQUOTED>\\t { addchar(false, '\t'); }
141+
<xNONQUOTED,xQUOTED>\\t { addchar(false, '\t'); }
136142
137-
<INITIAL,xNONQUOTED,xQUOTED>{unicode}+ { parseUnicode(yytext, yyleng); }
143+
<xNONQUOTED,xQUOTED>{unicode}+ { parseUnicode(yytext, yyleng); }
138144
139-
<INITIAL,xNONQUOTED,xQUOTED>\\u { yyerror("Unicode sequence is invalid"); }
145+
<xNONQUOTED,xQUOTED>\\u { yyerror("Unicode sequence is invalid"); }
140146
141-
<INITIAL,xNONQUOTED,xQUOTED>\\. { yyerror("Escape sequence is invalid"); }
147+
<xNONQUOTED,xQUOTED>\\. { yyerror("Escape sequence is invalid"); }
142148
143-
<INITIAL,xNONQUOTED,xQUOTED>\\ { yyerror("Unexpected end after backslesh"); }
149+
<xNONQUOTED,xQUOTED>\\ { yyerror("Unexpected end after backslesh"); }
144150
145151
<xQUOTED><<EOF>> { yyerror("Unexpected end of quoted string"); }
146152

sql/jsquery.sql

+17
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar \u0024 chara
175175
select '{ "a": "dollar \u0024 character" }'::jsonb @@ '* = "dollar $ character"';
176176
select '{ "a": "dollar $ character" }'::jsonb @@ '* = "dollar \u0024 character"';
177177
select 'a\r = "\n\""'::jsquery;
178+
select 'a\r = "\u0000"'::jsquery;
179+
select 'a\r = \u0000'::jsquery;
180+
select 'a\r = "\abcd"'::jsquery AS err;
181+
select 'a\r = "\\abcd"'::jsquery;
182+
select 'a\r = "x\u0000"'::jsquery;
183+
select 'a\r = x\u0000'::jsquery;
184+
select 'a\r = "x\abcd"'::jsquery AS err;
185+
select 'a\r = "x\\abcd"'::jsquery;
186+
select 'a\r = "x\u0000x"'::jsquery;
187+
select 'a\r = x\u0000x'::jsquery;
188+
select 'a\r = "x\abcdx"'::jsquery AS err;
189+
select 'a\r = "x\\abcdx"'::jsquery;
190+
select 'a\r = "\u0000x"'::jsquery;
191+
select 'a\r = \u0000x'::jsquery;
192+
select 'a\r = "\abcdx"'::jsquery AS err;
193+
select 'a\r = "\\abcdx"'::jsquery;
194+
select 'a\r = x"\\abcd"'::jsquery AS err;
178195

179196
---table and index
180197

0 commit comments

Comments
 (0)