xref: /php-src/ext/json/tests/bug54058.phpt (revision 32a1ebbd)
1--TEST--
2Bug #54058 (json_last_error() invalid UTF-8 produces wrong error)
3--FILE--
4<?php
5
6$bad_utf8 = quoted_printable_decode('=B0');
7
8json_encode($bad_utf8);
9var_dump(json_last_error(), json_last_error_msg());
10
11$a = new stdclass;
12$a->foo = quoted_printable_decode('=B0');
13json_encode($a);
14var_dump(json_last_error(), json_last_error_msg());
15
16$b = new stdclass;
17$b->foo = $bad_utf8;
18$b->bar = 1;
19json_encode($b);
20var_dump(json_last_error(), json_last_error_msg());
21
22$c = array(
23    'foo' => $bad_utf8,
24    'bar' => 1
25);
26json_encode($c);
27var_dump(json_last_error(), json_last_error_msg());
28
29?>
30--EXPECT--
31int(5)
32string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
33int(5)
34string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
35int(5)
36string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
37int(5)
38string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
39