stas Wed Jan 30 03:21:30 2008 UTC Modified files: /php-src/ext/json json.c utf8_to_utf16.c /php-src/ext/json/tests bug43941.phpt Log: fix #43941: invalid utf-8 not accepted http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.33&r2=1.34&diff_format=u Index: php-src/ext/json/json.c diff -u php-src/ext/json/json.c:1.33 php-src/ext/json/json.c:1.34 --- php-src/ext/json/json.c:1.33 Mon Dec 31 07:12:10 2007 +++ php-src/ext/json/json.c Wed Jan 30 03:21:30 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: json.c,v 1.33 2007/12/31 07:12:10 sebastian Exp $ */ +/* $Id: json.c,v 1.34 2008/01/30 03:21:30 stas Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -265,12 +265,17 @@ len = utf8_to_utf16(utf16, s.s, len); if (len <= 0) { - if (utf16) - { + if (utf16) { efree(utf16); } - - smart_str_appendl(buf, "\"\"", 2); + if(len < 0) { + if(!PG(display_errors)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UTF-8 sequence in argument"); + } + smart_str_appendl(buf, "null", 4); + } else { + smart_str_appendl(buf, "\"\"", 2); + } return; } } http://cvs.php.net/viewvc.cgi/php-src/ext/json/utf8_to_utf16.c?r1=1.2&r2=1.3&diff_format=u Index: php-src/ext/json/utf8_to_utf16.c diff -u php-src/ext/json/utf8_to_utf16.c:1.2 php-src/ext/json/utf8_to_utf16.c:1.3 --- php-src/ext/json/utf8_to_utf16.c:1.2 Thu Jul 12 09:55:41 2007 +++ php-src/ext/json/utf8_to_utf16.c Wed Jan 30 03:21:30 2008 @@ -39,7 +39,7 @@ for (;;) { c = utf8_decode_next(&utf8); if (c < 0) { - return UTF8_END ? the_index : UTF8_ERROR; + return (c == UTF8_END) ? the_index : UTF8_ERROR; } if (c < 0x10000) { w[the_index] = (unsigned short)c; http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug43941.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/json/tests/bug43941.phpt diff -u /dev/null php-src/ext/json/tests/bug43941.phpt:1.2 --- /dev/null Wed Jan 30 03:21:30 2008 +++ php-src/ext/json/tests/bug43941.phpt Wed Jan 30 03:21:30 2008 @@ -0,0 +1,21 @@ +--TEST-- +Bug #43941 (json_encode() invalid UTF-8) +--SKIPIF-- +<?php if (!extension_loaded("json")) print "skip"; ?> +--FILE-- +<?php + +var_dump(json_encode("abc")); +var_dump(json_encode("ab\xE0")); +var_dump(json_encode("ab\xE0c")); +var_dump(json_encode(array("ab\xE0", "ab\xE0c", "abc"))); + +echo "Done\n"; +?> +--EXPECTF-- +string(5) ""abc"" +string(4) "null" +string(4) "null" +string(17) "[null,null,"abc"]" +Done +
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php