xref: /PHP-7.0/ext/json/tests/bug54058.phpt (revision e5abc537)
1--TEST--
2Bug #54058 (json_last_error() invalid UTF-8 produces wrong error)
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7
8$bad_utf8 = quoted_printable_decode('=B0');
9
10json_encode($bad_utf8);
11var_dump(json_last_error(), json_last_error_msg());
12
13$a = new stdclass;
14$a->foo = quoted_printable_decode('=B0');
15json_encode($a);
16var_dump(json_last_error(), json_last_error_msg());
17
18$b = new stdclass;
19$b->foo = $bad_utf8;
20$b->bar = 1;
21json_encode($b);
22var_dump(json_last_error(), json_last_error_msg());
23
24$c = array(
25	'foo' => $bad_utf8,
26	'bar' => 1
27);
28json_encode($c);
29var_dump(json_last_error(), json_last_error_msg());
30
31?>
32--EXPECTF--
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"
39int(5)
40string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
41