/hphp/test/slow/ext_string/htmlspecialchars.php
PHP | 88 lines | 73 code | 12 blank | 3 comment | 2 complexity | 8bd3c5f04a03e8c9d2f3a333fd6e15f8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?hh
- function VS($x, $y) {
- var_dump($x === $y);
- if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
- var_dump(debug_backtrace()); }
- }
- function VERIFY($x) { VS($x != false, true); }
- // Php doesn't support \u escapes.
- function u($x) { return json_decode("\"" . $x . "\""); }
- //////////////////////////////////////////////////////////////////////
- function test_htmlspecialchars_decode() {
- $str = "<p>this -> "</p>";
- VS(htmlspecialchars_decode($str), "<p>this -> \"</p>");
- VS(htmlspecialchars_decode("<"), "<");
- VS(htmlspecialchars_decode(" "), " ");
- VS(htmlspecialchars_decode("& É Α '"),
- "& É Α '");
- }
- function test_htmlspecialchars() {
- VS(htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES),
- "<a href='test'>Test</a>");
- VS(bin2hex(htmlspecialchars("\xA0", ENT_COMPAT)), "");
- VS(bin2hex(htmlspecialchars("\xc2\xA0", ENT_COMPAT, "")), "c2a0");
- VS(bin2hex(htmlspecialchars("\xc2\xA0", ENT_COMPAT, "UTF-8")), "c2a0");
- $zfoo = "\0foo";
- VS(htmlspecialchars($zfoo, ENT_COMPAT), $zfoo);
- VS(fb_htmlspecialchars($zfoo, ENT_COMPAT), $zfoo);
- VS(fb_htmlspecialchars("abcdef'\"{}@gz", ENT_QUOTES,
- "", varray["z"]),
- "abcdef'"{}@gz");
- VS(fb_htmlspecialchars("abcdef'\"".u('\u00a1\uabcd'), ENT_FB_UTF8,
- "", varray["d"]),
- "abcdef'"¡ꯍ");
- VS(fb_htmlspecialchars("abcdef'\"".u('\u00a1\uabcd'), ENT_FB_UTF8_ONLY,
- "", varray["d"]),
- "abcdef'\"¡ꯍ");
- // The rest here expects RuntimeOption::Utf8izeReplace = true;
- $input =
- u('\u00a1')."\xc2\x41".
- u('\u0561')."\xd5\xe0".
- u('\u3862')."\xe3\x80\xf0".
- "\xf0\xa1\xa2\xa3".
- "\xf0\xa1\xa2\x41".
- "hello\x80world".
- "\xed\xa0\x80".
- "\xe0\x80\xbc".
- "\xc2";
- $tmp = $input;
- fb_utf8ize(inout $tmp);
- $sanitized = $tmp;
- VS(fb_htmlspecialchars($input, ENT_QUOTES, "UtF-8", varray[]),
- $sanitized);
- VS(fb_htmlspecialchars($input, ENT_FB_UTF8, "utf-8", varray[]),
- '¡�A'.
- 'ա��'.
- '㡢��'.
- '𡢣�A'.
- 'hello�world'.
- '�'.
- '�'.
- '�');
- VS(fb_htmlspecialchars($sanitized, ENT_QUOTES, "", varray[]),
- $sanitized);
- VS(fb_htmlspecialchars($zfoo, ENT_COMPAT, "UTF-8"), u('\ufffd')."foo");
- }
- <<__EntryPoint>>
- function main_htmlspecialchars() {
- test_htmlspecialchars_decode();
- test_htmlspecialchars();
- }