summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Adams2011-01-17 19:17:29 +0000
committerJoey Adams2011-01-17 19:17:29 +0000
commit59ad85e9165616e5de89b12465852ccf092f2e47 (patch)
tree999456033e9cd9cd227a860d32fc052e90f1814a
parent4869261b8a1ea6186b5d0c06d97c4296a2ce7bcf (diff)
Fixed UTF-16 surrogate pair calculation to properly handle cases like "\uD840\uDC00".
-rw-r--r--Makefile2
-rw-r--r--expected/unicode.out7
-rw-r--r--json.c2
-rw-r--r--sql/unicode.sql2
4 files changed, 11 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 65e8b12..c94fdf5 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ OBJS = json.o jsonpath.o json_io.o json_op.o util.o
DATA_built = json.sql
DATA = uninstall_json.sql
-REGRESS = init json validate condense orig json_path json_get json_set array_to_json
+REGRESS = init json validate condense orig json_path json_get json_set array_to_json unicode
ifdef USE_PGXS
PG_CONFIG = pg_config
diff --git a/expected/unicode.out b/expected/unicode.out
new file mode 100644
index 0000000..a9f78b5
--- /dev/null
+++ b/expected/unicode.out
@@ -0,0 +1,7 @@
+-- Make sure the surrogate pair calculation adds 0x10000 rather than ORing it.
+SELECT ascii(from_json($$ "\uD840\uDC00" $$));
+ ascii
+--------
+ 131072
+(1 row)
+
diff --git a/json.c b/json.c
index 3aa6ddd..ade2136 100644
--- a/json.c
+++ b/json.c
@@ -824,7 +824,7 @@ json_decode_string(const char **sp, size_t *length, bool strict)
s += 6;
- uc = 0x10000 | ((uc & 0x3FF) << 10) | (lc & 0x3FF);
+ uc = 0x10000 + (((uc & 0x3FF) << 10) | (lc & 0x3FF));
}
unicode_to_utf8(uc, (unsigned char *) buf);
diff --git a/sql/unicode.sql b/sql/unicode.sql
new file mode 100644
index 0000000..40e7b78
--- /dev/null
+++ b/sql/unicode.sql
@@ -0,0 +1,2 @@
+-- Make sure the surrogate pair calculation adds 0x10000 rather than ORing it.
+SELECT ascii(from_json($$ "\uD840\uDC00" $$));