diff options
author | Eddie Kohler <ekohler@gmail.com> | 2015-12-28 19:05:09 -0500 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2016-01-22 19:40:58 +0000 |
commit | 104876dd8e3ddb5cb46971a8e1be100ba7d9b432 (patch) | |
tree | a0b589bd2ca0f14a7b30d47181b5a998f2218687 /ext/json/tests | |
parent | 9b854ebab4ddd729a878b094268f639d2fa7b228 (diff) | |
download | php-git-104876dd8e3ddb5cb46971a8e1be100ba7d9b432.tar.gz |
json_encode: Escape U+2028 and U+2029 more often.
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.
Diffstat (limited to 'ext/json/tests')
-rw-r--r-- | ext/json/tests/json_encode_u2028_u2029.phpt | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ext/json/tests/json_encode_u2028_u2029.phpt b/ext/json/tests/json_encode_u2028_u2029.phpt new file mode 100644 index 0000000000..4b87e9b307 --- /dev/null +++ b/ext/json/tests/json_encode_u2028_u2029.phpt @@ -0,0 +1,36 @@ +--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"" |