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