fix jsonb multibyte character invisible problem

This commit is contained in:
gentle_hu
2021-09-02 20:46:39 +08:00
parent ecf980b67b
commit a16bd3946c
5 changed files with 15 additions and 1 deletions

View File

@ -2107,7 +2107,7 @@ void escape_json(StringInfo buf, const char *str)
appendStringInfo(buf, "\\u%04x", (int) *p);
} else {
for (int i = 0; i < charlen; i++) {
appendStringInfoCharMacro(buf, *p);
appendStringInfoCharMacro(buf, *(p + i));
}
}
break;

View File

@ -79,6 +79,12 @@ SELECT '"\uaBcD"'::json; -- OK, uppercase and lower case both OK
"\uaBcD"
(1 row)
SELECT '"哈1哈"'::jsonb; -- OK
jsonb
---------
"哈1哈"
(1 row)
-- Numbers.
SELECT '1'::json; -- OK
json

View File

@ -73,6 +73,12 @@ SELECT '"\u0000"'::jsonb; -- OK, legal escape
"\\u0000"
(1 row)
SELECT '"哈1哈"'::jsonb; -- OK
jsonb
---------
"哈1哈"
(1 row)
-- 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

View File

@ -12,6 +12,7 @@ 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
SELECT '"哈1哈"'::jsonb; -- OK
-- Numbers.
SELECT '1'::json; -- OK

View File

@ -11,6 +11,7 @@ SELECT '"\u"'::jsonb; -- ERROR, incomplete escape
SELECT '"\u00"'::jsonb; -- ERROR, incomplete escape
SELECT '"\u000g"'::jsonb; -- ERROR, g is not a hex digit
SELECT '"\u0000"'::jsonb; -- OK, legal escape
SELECT '"哈1哈"'::jsonb; -- OK
-- 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