xref: /PHP-7.3/ext/json/tests/bug61537.phpt (revision ded3d984)
1--TEST--
2Bug #61537 (json_encode() incorrectly truncates/discards information)
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7$invalid_utf8 = "\x9f";
8
9var_dump(json_encode($invalid_utf8));
10var_dump(json_last_error(), json_last_error_msg());
11
12var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR));
13var_dump(json_last_error(), json_last_error_msg());
14
15echo "\n";
16
17$invalid_utf8 = "an invalid sequen\xce in the middle of a string";
18
19var_dump(json_encode($invalid_utf8));
20var_dump(json_last_error(), json_last_error_msg());
21
22var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR));
23var_dump(json_last_error(), json_last_error_msg());
24
25?>
26--EXPECT--
27bool(false)
28int(5)
29string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
30string(4) "null"
31int(5)
32string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
33
34bool(false)
35int(5)
36string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
37string(4) "null"
38int(5)
39string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
40