json/jsonb inconsistence - 2

Started by Teodor Sigaevover 11 years ago4 messages
#1Teodor Sigaev
teodor@sigaev.ru

postgres=# select '["\u0000"]'::json->0;
?column?
----------
"\u0000"
(1 row)

Time: 1,294 ms
postgres=# select '["\u0000"]'::jsonb->0;
?column?
-----------
"\\u0000"
(1 row)

It seems to me that escape_json() is wrongly used in jsonb_put_escaped_value(),
right name of escape_json() is a escape_to_json().

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Teodor Sigaev (#1)
Re: json/jsonb inconsistence - 2

On 05/29/2014 08:00 AM, Teodor Sigaev wrote:

postgres=# select '["\u0000"]'::json->0;
?column?
----------
"\u0000"
(1 row)

Time: 1,294 ms
postgres=# select '["\u0000"]'::jsonb->0;
?column?
-----------
"\\u0000"
(1 row)

It seems to me that escape_json() is wrongly used in
jsonb_put_escaped_value(), right name of escape_json() is a
escape_to_json().

That's a bug. I will look into it. I think we might need to special-case
\u0000 on output, just as we do on input.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#2)
Re: json/jsonb inconsistence - 2

On 05/29/2014 08:15 AM, Andrew Dunstan wrote:

On 05/29/2014 08:00 AM, Teodor Sigaev wrote:

postgres=# select '["\u0000"]'::json->0;
?column?
----------
"\u0000"
(1 row)

Time: 1,294 ms
postgres=# select '["\u0000"]'::jsonb->0;
?column?
-----------
"\\u0000"
(1 row)

It seems to me that escape_json() is wrongly used in
jsonb_put_escaped_value(), right name of escape_json() is a
escape_to_json().

That's a bug. I will look into it. I think we might need to
special-case \u0000 on output, just as we do on input.

Actually, this is just the tip of the iceberg.

Here's what 9.3 does:

andrew=# select array_to_json(array['a','\u0000','b']::text[]);
array_to_json
---------------------
["a","\\u0000","b"]

I'm now wondering if we should pass though any unicode escape
(presumably validated to some extent). I guess we can't change this in
9.2/9.3 because it would be a behaviour change.

These unicode escapes have given us more trouble than any other part of
the JSON spec :-(

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Teodor Sigaev
teodor@sigaev.ru
In reply to: Andrew Dunstan (#3)
Re: json/jsonb inconsistence - 2

Actually, this is just the tip of the iceberg.

Funny, but
postgres=# select '\u0000'::text;
text
--------
\u0000
(1 row)

postgres=# select array['\u0000']::text[];
array
-------------
{"\\u0000"}

postgres=# select '{"\u0000"}'::text[];
text
---------
{u0000}

postgres=# select '{"\\u0000"}'::text[];
text
-------------
{"\\u0000"}

&%) I'm crazy about that. Suppose, we shouldn't worry about array type,
just make output the same for json/jsonb
--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers