From f63a3cf4ca0eaeb5ebf3789c123a870ce5b17df7 Mon Sep 17 00:00:00 2001 From: Ishjaap Singh Date: Wed, 2 Dec 2026 06:42:56 +0000 Subject: [PATCH v1] Don't drop a jsonpath word directly followed by a comment When an unquoted word in a jsonpath was directly followed by "/*", the scanner started the comment without returning the word, so the word was silently lost. For example, 'strict/**/$.a' was read as '$.a' in lax mode, and 'abc/**/1' was accepted as '1' instead of failing with a syntax error. Remove the special rule for "/*" after an unquoted word. The rule for a special character after a word then handles "/" like any other delimiter: it returns the word and leaves "/*" to be scanned as a comment in the initial state. --- src/backend/utils/adt/jsonpath_scan.l | 5 ---- src/test/regress/expected/jsonpath.out | 41 ++++++++++++++++++++++++++ src/test/regress/sql/jsonpath.sql | 9 ++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/backend/utils/adt/jsonpath_scan.l b/src/backend/utils/adt/jsonpath_scan.l index e4fadcc2e69..a1de4cc9934 100644 --- a/src/backend/utils/adt/jsonpath_scan.l +++ b/src/backend/utils/adt/jsonpath_scan.l @@ -129,11 +129,6 @@ hex_fail \\x{hexdigit}{0,1} return checkKeyword(yyscanner); } -\/\* { - yylval->str = yyextra->scanstring; - BEGIN xc; - } - ({special}|\") { yylval->str = yyextra->scanstring; yyless(0); diff --git a/src/test/regress/expected/jsonpath.out b/src/test/regress/expected/jsonpath.out index ea971e79854..523ee85bad0 100644 --- a/src/test/regress/expected/jsonpath.out +++ b/src/test/regress/expected/jsonpath.out @@ -1458,6 +1458,47 @@ select '0x_42F'::jsonpath; ERROR: syntax error at end of jsonpath input LINE 1: select '0x_42F'::jsonpath; ^ +-- a comment directly after an unquoted word must not drop the word +select 'strict/**/$.a'::jsonpath; + jsonpath +-------------- + strict $."a" +(1 row) + +select 'lax/* comment */$.a'::jsonpath; + jsonpath +---------- + $."a" +(1 row) + +select '$.a/**/.b'::jsonpath; + jsonpath +----------- + $."a"."b" +(1 row) + +select '$.a/**/'::jsonpath; + jsonpath +---------- + $."a" +(1 row) + +select '$.a.type/**/()'::jsonpath; + jsonpath +-------------- + $."a".type() +(1 row) + +select '$ ? (@ == true/**/)'::jsonpath; + jsonpath +--------------- + $?(@ == true) +(1 row) + +select 'abc/**/1'::jsonpath; +ERROR: syntax error at end of jsonpath input +LINE 1: select 'abc/**/1'::jsonpath; + ^ -- test non-error-throwing API SELECT str as jsonpath, pg_input_is_valid(str,'jsonpath') as ok, diff --git a/src/test/regress/sql/jsonpath.sql b/src/test/regress/sql/jsonpath.sql index 44178d8b45a..dcb4bd39e5c 100644 --- a/src/test/regress/sql/jsonpath.sql +++ b/src/test/regress/sql/jsonpath.sql @@ -292,6 +292,15 @@ select '0o_273'::jsonpath; select '0x_42F'::jsonpath; +-- a comment directly after an unquoted word must not drop the word +select 'strict/**/$.a'::jsonpath; +select 'lax/* comment */$.a'::jsonpath; +select '$.a/**/.b'::jsonpath; +select '$.a/**/'::jsonpath; +select '$.a.type/**/()'::jsonpath; +select '$ ? (@ == true/**/)'::jsonpath; +select 'abc/**/1'::jsonpath; + -- test non-error-throwing API SELECT str as jsonpath, -- 2.43.0