iliaa           Thu Apr 19 22:49:12 2007 UTC

  Modified files:              
    /php-src/ext/json   JSON_parser.c 
  Log:
  
  MFB:  Fixed bug #41067 (json_encode() problem with UTF-16 input).
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/JSON_parser.c?r1=1.8&r2=1.9&diff_format=u
Index: php-src/ext/json/JSON_parser.c
diff -u php-src/ext/json/JSON_parser.c:1.8 php-src/ext/json/JSON_parser.c:1.9
--- php-src/ext/json/JSON_parser.c:1.8  Mon Apr 16 16:52:20 2007
+++ php-src/ext/json/JSON_parser.c      Thu Apr 19 22:49:11 2007
@@ -316,6 +316,25 @@
         smart_str_appendc(buf, 0xc0 | (utf16 >> 6));
         smart_str_appendc(buf, 0x80 | (utf16 & 0x3f));
     }
+    else if ((utf16 & 0xfc00) == 0xdc00
+                && buf->len >= 3
+                && ((unsigned char) buf->c[buf->len - 3]) == 0xed
+                && ((unsigned char) buf->c[buf->len - 2] & 0xf0) == 0xa0
+                && ((unsigned char) buf->c[buf->len - 1] & 0xc0) == 0x80)
+    {
+        /* found surrogate pair */
+        unsigned long utf32;
+
+        utf32 = (((buf->c[buf->len - 2] & 0xf) << 16)
+                    | ((buf->c[buf->len - 1] & 0x3f) << 10)
+                    | (utf16 & 0x3ff)) + 0x10000;
+        buf->len -= 3;
+
+        smart_str_appendc(buf, 0xf0 | (utf32 >> 18));
+        smart_str_appendc(buf, 0x80 | ((utf32 >> 12) & 0x3f));
+        smart_str_appendc(buf, 0x80 | ((utf32 >> 6) & 0x3f));
+        smart_str_appendc(buf, 0x80 | (utf32 & 0x3f));
+    }
     else
     {
         smart_str_appendc(buf, 0xe0 | (utf16 >> 12));

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to