summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/json.c3
-rw-r--r--ext/json/tests/bug54058.phpt35
2 files changed, 37 insertions, 1 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 5f3e1a854b..ec76c1d5f3 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -431,7 +431,6 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
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:
@@ -567,6 +566,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);
diff --git a/ext/json/tests/bug54058.phpt b/ext/json/tests/bug54058.phpt
new file mode 100644
index 0000000000..3b1136bdd9
--- /dev/null
+++ b/ext/json/tests/bug54058.phpt
@@ -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)