mirror of
https://github.com/php/php-src.git
synced 2024-09-23 19:07:26 +00:00
104876dd8e
These characters are illegal in Javascript, so leaving them unescaped is risky. The default encoder ($flags = 0) is fine, but the encoder with JSON_UNESCAPED_UNICODE flag is not. In case anyone wants the ability to leave these characters unescaped, provide JSON_UNESCAPED_LINE_TERMINATORS.
37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
--TEST--
|
||
json_encode() tests for U+2028, U+2029
|
||
--SKIPIF--
|
||
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||
--FILE--
|
||
<?php
|
||
var_dump(json_encode(array("a\xC3\xA1b")));
|
||
var_dump(json_encode(array("a\xC3\xA1b"), JSON_UNESCAPED_UNICODE));
|
||
var_dump(json_encode("a\xE2\x80\xA7b"));
|
||
var_dump(json_encode("a\xE2\x80\xA7b", JSON_UNESCAPED_UNICODE));
|
||
var_dump(json_encode("a\xE2\x80\xA8b"));
|
||
var_dump(json_encode("a\xE2\x80\xA8b", JSON_UNESCAPED_UNICODE));
|
||
var_dump(json_encode("a\xE2\x80\xA8b", JSON_UNESCAPED_LINE_TERMINATORS));
|
||
var_dump(json_encode("a\xE2\x80\xA8b", JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_LINE_TERMINATORS));
|
||
var_dump(json_encode("a\xE2\x80\xA9b"));
|
||
var_dump(json_encode("a\xE2\x80\xA9b", JSON_UNESCAPED_UNICODE));
|
||
var_dump(json_encode("a\xE2\x80\xA9b", JSON_UNESCAPED_LINE_TERMINATORS));
|
||
var_dump(json_encode("a\xE2\x80\xA9b", JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_LINE_TERMINATORS));
|
||
var_dump(json_encode("a\xE2\x80\xAAb"));
|
||
var_dump(json_encode("a\xE2\x80\xAAb", JSON_UNESCAPED_UNICODE));
|
||
?>
|
||
--EXPECT--
|
||
string(12) "["a\u00e1b"]"
|
||
string(8) "["aáb"]"
|
||
string(10) ""a\u2027b""
|
||
string(7) ""a‧b""
|
||
string(10) ""a\u2028b""
|
||
string(10) ""a\u2028b""
|
||
string(10) ""a\u2028b""
|
||
string(7) ""a
b""
|
||
string(10) ""a\u2029b""
|
||
string(10) ""a\u2029b""
|
||
string(10) ""a\u2029b""
|
||
string(7) ""a
b""
|
||
string(10) ""a\u202ab""
|
||
string(7) ""ab""
|