BUG #18510: jsonpath does not support trailing backslash at the end of the query - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18510: jsonpath does not support trailing backslash at the end of the query
Date
Msg-id 18510-744a9f0c859e3b45@postgresql.org
Whole thread Raw
Responses Re: BUG #18510: jsonpath does not support trailing backslash at the end of the query
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18510
Logged by:          Lex Vorona
Email address:      voronaam@gmail.com
PostgreSQL version: 16.3
Operating system:   Linux (Ubuntu)
Description:

Note that JSONPATH documentation states [1]:

>  to write a backslash itself, you must write \\

It works for a backslash as long as it is not the last character in the
input string.

Simplest way to reproduce:

psql (16.3 (Ubuntu 16.3-1.pgdg22.04+1))

postgres=# select '$.field ? (@ like_regex "a\\b")'::jsonpath; -- works
            jsonpath             
---------------------------------
 $."field"?(@ like_regex "a\\b")
(1 row)


postgres=# select '$.field ? (@ like_regex "a\\")'::jsonpath; -- does not
work
ERROR:  invalid regular expression: invalid escape \ sequence
LINE 1: select '$.field ? (@ like_regex "a\\")'::jsonpath;
               ^

Also reproducible with functions like jsonb_path_exists(...) which
automatically cast parameters to jsonpath.


1:
https://www.postgresql.org/docs/current/datatype-json.html#DATATYPE-JSONPATH


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18509: Logical decoding behaves badly when processing a change record for a table with altered column
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #18510: jsonpath does not support trailing backslash at the end of the query