From fc07bd4841a9b905cfd2cca7e11be83eda7a31e8 Mon Sep 17 00:00:00 2001 From: "Pierre G. Bogossian" Date: Fri, 26 Aug 2016 18:46:00 +0200 Subject: [PATCH 1/3] Fix for a bug in unicode surrogate pair handling eg: the JSON string "\ud841\udf31" should contain the character with the unicode scalar value U+20731, not U+10731 --- json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json.c b/json.c index deef49ff..da137846 100644 --- a/json.c +++ b/json.c @@ -355,8 +355,8 @@ json_value * json_parse_ex (json_settings * settings, uc_b1 = (uc_b1 << 4) | uc_b2; uc_b2 = (uc_b3 << 4) | uc_b4; uchar2 = (uc_b1 << 8) | uc_b2; - - uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); + + uchar = 0x010000 + ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); } if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F)) From 0c6db0d785834abd588d401f66bb085a7e6ee277 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 29 Dec 2021 22:06:41 +0100 Subject: [PATCH 2/3] Add more testing for UTF-16 surrogate pairs --- tests/test.c | 2 +- tests/valid-0012.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test.c b/tests/test.c index 9d2c4fba..c006175b 100644 --- a/tests/test.c +++ b/tests/test.c @@ -224,7 +224,7 @@ int main(void) JSON_COMPARE_STRING(0, "\\r\\n", "\r\n"); JSON_COMPARE_STRING(2, "abc \0 123", "abc \0 123"); /* TODO: should this really be disallowed? */ JSON_COMPARE_STRING(0, "abc \\u0000 123", "abc \0 123"); - JSON_COMPARE_STRING(1, "\\ud841\\udf31", "𠜱"); /* TODO: this should actually succeed after PR #58 is merged */ + JSON_COMPARE_STRING(0, "\\ud841\\udf31", "𠜱"); if(0 != json_verify( "valid-%04u.json", 13, 0, 0)){ exit_code = EXIT_FAILURE; } if(0 != json_verify( "invalid-%04u.json", 10, 0, 1)){ exit_code = EXIT_FAILURE; } diff --git a/tests/valid-0012.json b/tests/valid-0012.json index 8c3b697d..ef24f254 100644 --- a/tests/valid-0012.json +++ b/tests/valid-0012.json @@ -1,5 +1,6 @@ { "WHITE FROWNING FACE (U+2639)": "\ud83d\ude1e", +"CJK Unified Ideograph-20731 (U+20731)": "\ud841\udf31", "WIDE ALPHABET": "\uff20\uff21\uff22\uff23\uff24\uff25\uff26\uff27\uff28\uff29\uff2a\uff2b\uff2c\uff2d\uff2e\uff2f\uff30\uff31\uff32\uff33\uff34\uff35\uff36\uff37\uff38\uff39\uff3a", "Vive Unicode": "\ud835\udce5\ud835\udcf2\ud835\udcff\ud835\udcee \ud835\udce4\ud835\udcf7\ud835\udcf2\ud835\udcec\ud835\udcf8\ud835\udced\ud835\udcee" } From 4f4a6642c2d9fcc30fe3382c02607caf9519ab8e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 29 Dec 2021 22:13:28 +0100 Subject: [PATCH 3/3] Fix compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit json.c: In function ‘json_parse_ex’: json.c:359:42: error: suggest parentheses around arithmetic in operand of ‘|’ [-Werror=parentheses] 359 | uchar = 0x010000 + ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ --- json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json.c b/json.c index da137846..3dff0461 100644 --- a/json.c +++ b/json.c @@ -355,8 +355,8 @@ json_value * json_parse_ex (json_settings * settings, uc_b1 = (uc_b1 << 4) | uc_b2; uc_b2 = (uc_b3 << 4) | uc_b4; uchar2 = (uc_b1 << 8) | uc_b2; - - uchar = 0x010000 + ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); + + uchar = 0x010000 + (((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF)); } if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F))