pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix jsonb Unicode escape processing, and in consequence disallow
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix jsonb Unicode escape processing, and in consequence disallow
@ 2015-01-30 19:45  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2015-01-30 19:45 UTC (permalink / raw)
  To: pgsql-committers

Fix jsonb Unicode escape processing, and in consequence disallow \u0000.

We've been trying to support \u0000 in JSON values since commit
78ed8e03c67d7333, and have introduced increasingly worse hacks to try to
make it work, such as commit 0ad1a816320a2b53.  However, it fundamentally
can't work in the way envisioned, because the stored representation looks
the same as for \\u0000 which is not the same thing at all.  It's also
entirely bogus to output \u0000 when de-escaped output is called for.

The right way to do this would be to store an actual 0x00 byte, and then
throw error only if asked to produce de-escaped textual output.  However,
getting to that point seems likely to take considerable work and may well
never be practical in the 9.4.x series.

To preserve our options for better behavior while getting rid of the nasty
side-effects of 0ad1a816320a2b53, revert that commit in toto and instead
throw error if \u0000 is used in a context where it needs to be de-escaped.
(These are the same contexts where non-ASCII Unicode escapes throw error
if the database encoding isn't UTF8, so this behavior is by no means
without precedent.)

In passing, make both the \u0000 case and the non-ASCII Unicode case report
ERRCODE_UNTRANSLATABLE_CHARACTER / "unsupported Unicode escape sequence"
rather than claiming there's something wrong with the input syntax.

Back-patch to 9.4, where we have to do something because 0ad1a816320a2b53
broke things for many cases having nothing to do with \u0000.  9.3 also has
bogus behavior, but only for that specific escape value, so given the lack
of field complaints it seems better to leave 9.3 alone.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/451d2808151e56c2c70893b8c3ee72af393a9f1d

Modified Files
--------------
doc/src/sgml/json.sgml                |   19 ++++----
doc/src/sgml/release-9.4.sgml         |   16 -------
src/backend/utils/adt/json.c          |   49 ++++++-------------
src/test/regress/expected/json.out    |   58 ++++++++++++++++-------
src/test/regress/expected/json_1.out  |   62 +++++++++++++++++-------
src/test/regress/expected/jsonb.out   |   78 +++++++++++++++++++++---------
src/test/regress/expected/jsonb_1.out |   84 +++++++++++++++++++++++----------
src/test/regress/sql/json.sql         |   18 +++----
src/test/regress/sql/jsonb.sql        |   26 +++++-----
9 files changed, 250 insertions(+), 160 deletions(-)


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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix jsonb Unicode escape processing, and in consequence disallow
@ 2015-01-30 19:45  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2015-01-30 19:45 UTC (permalink / raw)
  To: pgsql-committers

Fix jsonb Unicode escape processing, and in consequence disallow \u0000.

We've been trying to support \u0000 in JSON values since commit
78ed8e03c67d7333, and have introduced increasingly worse hacks to try to
make it work, such as commit 0ad1a816320a2b53.  However, it fundamentally
can't work in the way envisioned, because the stored representation looks
the same as for \\u0000 which is not the same thing at all.  It's also
entirely bogus to output \u0000 when de-escaped output is called for.

The right way to do this would be to store an actual 0x00 byte, and then
throw error only if asked to produce de-escaped textual output.  However,
getting to that point seems likely to take considerable work and may well
never be practical in the 9.4.x series.

To preserve our options for better behavior while getting rid of the nasty
side-effects of 0ad1a816320a2b53, revert that commit in toto and instead
throw error if \u0000 is used in a context where it needs to be de-escaped.
(These are the same contexts where non-ASCII Unicode escapes throw error
if the database encoding isn't UTF8, so this behavior is by no means
without precedent.)

In passing, make both the \u0000 case and the non-ASCII Unicode case report
ERRCODE_UNTRANSLATABLE_CHARACTER / "unsupported Unicode escape sequence"
rather than claiming there's something wrong with the input syntax.

Back-patch to 9.4, where we have to do something because 0ad1a816320a2b53
broke things for many cases having nothing to do with \u0000.  9.3 also has
bogus behavior, but only for that specific escape value, so given the lack
of field complaints it seems better to leave 9.3 alone.

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/4cbf390d5f0339f9846d4492b15f98b41bfffe12

Modified Files
--------------
doc/src/sgml/json.sgml                |   19 +++++----
doc/src/sgml/release-9.4.sgml         |   16 --------
src/backend/utils/adt/json.c          |   40 +++++--------------
src/test/regress/expected/json.out    |   58 +++++++++++++++++++--------
src/test/regress/expected/json_1.out  |   62 ++++++++++++++++++++---------
src/test/regress/expected/jsonb.out   |   64 ++++++++++++++++++++++++++----
src/test/regress/expected/jsonb_1.out |   70 +++++++++++++++++++++++++++------
src/test/regress/sql/json.sql         |   18 ++++-----
src/test/regress/sql/jsonb.sql        |   18 +++++++--
9 files changed, 245 insertions(+), 120 deletions(-)


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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2015-01-30 19:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-30 19:45 pgsql: Fix jsonb Unicode escape processing, and in consequence disallow Tom Lane <tgl@sss.pgh.pa.us>
2015-01-30 19:45 pgsql: Fix jsonb Unicode escape processing, and in consequence disallow Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox