pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow Unicode escapes in any server encoding, not only UTF-8.
Date: Fri, 06 Mar 2020 19:17:56 +0000
Message-ID: <E1jAITs-0001KB-DO@gemulon.postgresql.org> (raw)

Allow Unicode escapes in any server encoding, not only UTF-8.

SQL includes provisions for numeric Unicode escapes in string
literals and identifiers.  Previously we only accepted those
if they represented ASCII characters or the server encoding
was UTF-8, making the conversion to internal form trivial.
This patch adjusts things so that we'll call the appropriate
encoding conversion function in less-trivial cases, allowing
the escape sequence to be accepted so long as it corresponds
to some character available in the server encoding.

This also applies to processing of Unicode escapes in JSONB.
However, the old restriction still applies to client-side
JSON processing, since that hasn't got access to the server's
encoding conversion infrastructure.

This patch includes some lexer infrastructure that simplifies
throwing errors with error cursors pointing into the middle of
a string (or other complex token).  For the moment I only used
it for errors relating to Unicode escapes, but we might later
expand the usage to some other cases.

Patch by me, reviewed by John Naylor.

Discussion: https://postgr.es/m/2393.1578958316@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a6525588b7c21fd8539e9a43ec9c5c245ed1cc91

Modified Files
--------------
doc/src/sgml/json.sgml                            |  19 ++--
doc/src/sgml/syntax.sgml                          | 100 ++++++++---------
src/backend/parser/parser.c                       |  74 ++++++------
src/backend/parser/scan.l                         | 131 +++++++++++++++++++---
src/backend/utils/adt/jsonpath_scan.l             |  45 ++------
src/backend/utils/adt/xml.c                       |  24 +---
src/backend/utils/mb/mbutils.c                    | 105 +++++++++++++++++
src/common/jsonapi.c                              |  58 ++++++----
src/include/mb/pg_wchar.h                         |  17 +++
src/include/parser/scanner.h                      |  16 +++
src/test/regress/expected/json_encoding.out       |  15 +++
src/test/regress/expected/json_encoding_1.out     |  39 ++++---
src/test/regress/expected/json_encoding_2.out     |   9 ++
src/test/regress/expected/jsonpath_encoding.out   |  15 +++
src/test/regress/expected/jsonpath_encoding_1.out |  33 ++++--
src/test/regress/expected/jsonpath_encoding_2.out |   9 ++
src/test/regress/expected/strings.out             |  83 +++++++++++++-
src/test/regress/sql/json_encoding.sql            |  13 ++-
src/test/regress/sql/jsonpath_encoding.sql        |  13 ++-
src/test/regress/sql/strings.sql                  |  20 ++++
20 files changed, 612 insertions(+), 226 deletions(-)



Message-ID: <E1jAITs-0001KB-DO@gemulon.postgresql.org>
Permalink:  ../E1jAITs-0001KB-DO@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1jAITs-0001KB-DO@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Allow Unicode escapes in any server encoding, not only UTF-8.
  In-Reply-To: <E1jAITs-0001KB-DO@gemulon.postgresql.org>
  References: <E1jAITs-0001KB-DO@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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