php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #67055
Patch patch_json.diff revision 2014-04-10 12:51 UTC by mail+bugs dot php dot net at kazik dot de

Patch patch_json.diff for JSON related Bug #67055

Patch version 2014-04-10 12:51 UTC

Return to Bug #67055 | Download this patch
Patch Revisions:

Developer: mail+bugs.php.net@kazik.de

--- ext/json/json.c_old	2014-04-10 14:14:22.344951081 +0200
+++ ext/json/json.c	2014-04-10 14:39:22.672224663 +0200
@@ -456,7 +456,7 @@
 
 	while (pos < len)
 	{
-		us = (options & PHP_JSON_UNESCAPED_UNICODE) ? s[pos++] : utf16[pos++];
+		us = (options & PHP_JSON_UNESCAPED_UNICODE) ? ((unsigned char *)s)[pos++] : utf16[pos++];
 
 		switch (us)
 		{
@@ -533,9 +533,14 @@
 				break;
 
 			default:
-				if (us >= ' ' && ((options & PHP_JSON_UNESCAPED_UNICODE) || (us & 127) == us)) {
+			        // no need to check length for s[pos], since due to the previos utf-8 validation it's gurantees that a 0xc2 char is followed by a second one
+				if (us >= 0x20 && us != 0x7f && (((options & PHP_JSON_UNESCAPED_UNICODE) && !(us == 0xc2 && ((unsigned char *)s)[pos] >= 0x80 && ((unsigned char *)s)[pos] <= 0x9f)) || (us < 0x80))) {
 					smart_str_appendc(buf, (unsigned char) us);
 				} else {
+				        if((options & PHP_JSON_UNESCAPED_UNICODE) && us == 0xc2 && ((unsigned char *)s)[pos] >= 0x80 && ((unsigned char *)s)[pos] <= 0x9f){
+				                // saw \u0080-\u009f in utf8-encoding, recompose in one character
+				                us = ((unsigned char *)s)[pos++];
+				        }
 					smart_str_appendl(buf, "\\u", 2);
 					smart_str_appendc(buf, digits[(us & 0xf000) >> 12]);
 					smart_str_appendc(buf, digits[(us & 0xf00)  >> 8]);
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jan 26 10:01:23 2021 UTC