Commit: 7bbd5521d28ee77c5a8df80174f52dad0112e872 Author: Stanislav Malyshev <s...@php.net> Tue, 1 May 2012 23:51:41 -0700 Parents: 93192ec56df762341125f257cc61ab0c3e64ea76 Branches: PHP-5.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7bbd5521d28ee77c5a8df80174f52dad0112e872 Log: Revert "Fix bug #61537 (json_encode() incorrectly truncates/discards information) and" This reverts commit cb2a1c71c96d7c9b2ee03d77beae0c8e0d385f1b. The fix is not correct, not fixed after discussion on github. Please fix the issues and reapply the patch Bugs: https://bugs.php.net/61537 Changed paths: M NEWS M ext/json/json.c M ext/json/php_json.h A ext/json/tests/bug43941.phpt M ext/json/tests/bug54058.phpt D ext/json/tests/bug61537.phpt Diff: diff --git a/NEWS b/NEWS index 11251eb..d538460 100644 --- a/NEWS +++ b/NEWS @@ -74,10 +74,6 @@ PHP NEWS . Fixed bug #61487 (Incorrent bounds checking in grapheme_strpos). (Stas) -- JSON - . Fixed bug #61537 (json_encode() incorrectly truncates/discards - information). (Adam) - - Libxml: . Fixed bug #61617 (Libxml tests failed(ht is already destroyed)). (Laruence) diff --git a/ext/json/json.c b/ext/json/json.c index 853611e..fc1fcb7 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -96,7 +96,6 @@ static PHP_MINIT_FUNCTION(json) REGISTER_LONG_CONSTANT("JSON_UNESCAPED_SLASHES", PHP_JSON_UNESCAPED_SLASHES, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("JSON_PRETTY_PRINT", PHP_JSON_PRETTY_PRINT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("JSON_UNESCAPED_UNICODE", PHP_JSON_UNESCAPED_UNICODE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("JSON_PARTIAL_OUTPUT_ON_ERROR", PHP_JSON_PARTIAL_OUTPUT_ON_ERROR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("JSON_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, CONST_CS | CONST_PERSISTENT); @@ -390,7 +389,9 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR } if (ulen < 0) { JSON_G(error_code) = PHP_JSON_ERROR_UTF8; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UTF-8 sequence in argument"); + 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); @@ -688,11 +689,7 @@ static PHP_FUNCTION(json_encode) php_json_encode(&buf, parameter, options TSRMLS_CC); - if (JSON_G(error_code) != PHP_JSON_ERROR_NONE && options ^ PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { - ZVAL_FALSE(return_value); - } else { - ZVAL_STRINGL(return_value, buf.c, buf.len, 1); - } + ZVAL_STRINGL(return_value, buf.c, buf.len, 1); smart_str_free(&buf); } diff --git a/ext/json/php_json.h b/ext/json/php_json.h index 20426c0..ef3e4b5 100644 --- a/ext/json/php_json.h +++ b/ext/json/php_json.h @@ -63,7 +63,6 @@ extern zend_class_entry *php_json_serializable_ce; #define PHP_JSON_UNESCAPED_SLASHES (1<<6) #define PHP_JSON_PRETTY_PRINT (1<<7) #define PHP_JSON_UNESCAPED_UNICODE (1<<8) -#define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9) /* Internal flags */ #define PHP_JSON_OUTPUT_ARRAY 0 diff --git a/ext/json/tests/bug43941.phpt b/ext/json/tests/bug43941.phpt new file mode 100644 index 0000000..0f86d1d --- /dev/null +++ b/ext/json/tests/bug43941.phpt @@ -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 + diff --git a/ext/json/tests/bug54058.phpt b/ext/json/tests/bug54058.phpt index 08c7f57..3b1136b 100644 --- a/ext/json/tests/bug54058.phpt +++ b/ext/json/tests/bug54058.phpt @@ -29,14 +29,7 @@ json_encode($c); var_dump(json_last_error()); ?> --EXPECTF-- -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d int(5) - -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d int(5) - -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d int(5) - -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d int(5) diff --git a/ext/json/tests/bug61537.phpt b/ext/json/tests/bug61537.phpt deleted file mode 100644 index e2abdda..0000000 --- a/ext/json/tests/bug61537.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -Bug #61537 (json_encode() incorrectly truncates/discards information) ---SKIPIF-- -<?php if (!extension_loaded("json")) print "skip"; ?> ---FILE-- -<?php -$invalid_utf8 = "\x9f"; -var_dump(json_encode($invalid_utf8), json_last_error()); -var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR), json_last_error()); - -$invalid_utf8 = "an invalid sequen\xce in the middle of a string"; -var_dump(json_encode($invalid_utf8), json_last_error()); -var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR), json_last_error()); -?> ---EXPECTF-- -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d -bool(false) -int(5) - -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d -string(4) "null" -int(5) - -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d -bool(false) -int(5) - -Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d -string(4) "null" -int(5) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php