-- -- encoding-sensitive tests for json and jsonb --
-- We provide expected-results files for UTF8 (json_encoding.out) -- and for SQL_ASCII (json_encoding_1.out). Skip otherwise. SELECT getdatabaseencoding() NOTIN ('UTF8', 'SQL_ASCII') AS skip_test \gset
\if :skip_test
\quit
\endif
SELECT getdatabaseencoding(); -- just to label the results files
-- first json
-- basic unicode input SELECT'"\u"'::json; -- ERROR, incomplete escape SELECT'"\u00"'::json; -- ERROR, incomplete escape SELECT'"\u000g"'::json; -- ERROR, g is not a hex digit SELECT'"\u0000"'::json; -- OK, legal escape SELECT'"\uaBcD"'::json; -- OK, uppercase and lower case both OK
-- basic unicode input SELECT'"\u"'::jsonb; -- ERROR, incomplete escape SELECT'"\u00"'::jsonb; -- ERROR, incomplete escape SELECT'"\u000g"'::jsonb; -- ERROR, g is not a hex digit SELECT'"\u0045"'::jsonb; -- OK, legal escape SELECT'"\u0000"'::jsonb; -- ERROR, we don't support U+0000 -- use octet_length here so we don't get an odd unicode char in the -- output SELECT octet_length('"\uaBcD"'::jsonb::text); -- OK, uppercase and lower case both OK
-- handling of unicode surrogate pairs
SELECT octet_length((jsonb '{ "a": "\ud83d\ude04\ud83d\udc36" }' -> 'a')::text) AS correct_in_utf8; SELECT jsonb '{ "a": "\ud83d\ud83d" }' -> 'a'; -- 2 high surrogates in a row SELECT jsonb '{ "a": "\ude04\ud83d" }' -> 'a'; -- surrogates in wrong order SELECT jsonb '{ "a": "\ud83dX" }' -> 'a'; -- orphan high surrogate SELECT jsonb '{ "a": "\ude04X" }' -> 'a'; -- orphan low surrogate
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.