Re: JSON validation behavior - Mailing list pgsql-hackers

From Tom Lane
Subject Re: JSON validation behavior
Date
Msg-id 20136.1540396473@sss.pgh.pa.us
Whole thread Raw
In response to Re: JSON validation behavior  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: JSON validation behavior  (Sergei Kornilov <sk@zsrv.org>)
Re: JSON validation behavior  (Andrew Dunstan <andrew.dunstan@2ndquadrant.com>)
List pgsql-hackers
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> The following does seem buggy though:
> select json '{ "a": "null \u0000 escape"}' -> 'a' as fails;

Perhaps, but AFAICS it's entirely accidental that any variant of this
doesn't fail.  Although this manages not to fail:

regression=# select json '{ "a": "null \u0000 escape"}' ;
             json             
------------------------------
 { "a": "null \u0000 escape"}
(1 row)

this does:

regression=# select jsonb '{ "a": "null \u0000 escape"}' ;
ERROR:  unsupported Unicode escape sequence

The error message is actually being thrown in the JSON parser, and it
only doesn't get thrown if the parser knows that it's just error-checking
the data and not producing any converted output (cf the
"if (lex->strval != NULL)" block starting at json.c:832).  It actually
seems to me that this behavior is a bug, in that there are a bunch of
error checks there (not only this one) that are skipped in the allegedly
"error checking only" path.

But anyway, making it work as suggested here would take a substantial
amount of refactoring, and it would not (I think) work anyway for jsonb,
so it doesn't quite seem worth a lot of work.  I could get behind fixing
it to always throw the error, but that's not what Sergei was hoping for.

            regards, tom lane


pgsql-hackers by date:

Previous
From: Sandeep Thakkar
Date:
Subject: Re: Problem with EDB 11.0 Windows x64 distributions
Next
From: Sergei Kornilov
Date:
Subject: Re: JSON validation behavior