1
0
mirror of https://github.com/php/php-src.git synced 2026-04-25 17:08:14 +02:00

Fix Bug #54058, invalid utf-8 doesn't set json_encode() in all cases

This commit is contained in:
Scott MacVicar
2011-02-21 08:09:02 +00:00
parent 2a6968e43a
commit ecb9d8019c
2 changed files with 37 additions and 1 deletions
+2 -1
View File
@@ -538,7 +538,6 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio
PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */
{
JSON_G(error_code) = PHP_JSON_ERROR_NONE;
switch (Z_TYPE_P(val))
{
case IS_NULL:
@@ -680,6 +679,8 @@ static PHP_FUNCTION(json_encode)
return;
}
JSON_G(error_code) = PHP_JSON_ERROR_NONE;
php_json_encode(&buf, parameter, options TSRMLS_CC);
ZVAL_STRINGL(return_value, buf.c, buf.len, 1);
+35
View File
@@ -0,0 +1,35 @@
--TEST--
Bug #54058 (json_last_error() invalid UTF-8 produces wrong error)
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
--FILE--
<?php
$bad_utf8 = quoted_printable_decode('=B0');
json_encode($bad_utf8);
var_dump(json_last_error());
$a = new stdclass;
$a->foo = quoted_printable_decode('=B0');
json_encode($a);
var_dump(json_last_error());
$b = new stdclass;
$b->foo = $bad_utf8;
$b->bar = 1;
json_encode($b);
var_dump(json_last_error());
$c = array(
'foo' => $bad_utf8,
'bar' => 1
);
json_encode($c);
var_dump(json_last_error());
?>
--EXPECTF--
int(5)
int(5)
int(5)
int(5)