mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
New and fixed html tests. Tested in Windows, Linux and Linux 64.
This commit is contained in:
parent
e6f4ec2f07
commit
3aaaf77a0e
@ -16,8 +16,10 @@ output_handler=
|
||||
<?php
|
||||
mb_internal_encoding('Shift_JIS');
|
||||
print mb_internal_encoding()."\n";
|
||||
var_dump(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, ''));
|
||||
var_dump(bin2hex(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, '')));
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
SJIS
|
||||
string(6) "、。,"
|
||||
string(12) "814181428143"
|
||||
===DONE===
|
||||
|
@ -14,8 +14,10 @@ output_handler=
|
||||
<?php
|
||||
mb_internal_encoding('cp1251');
|
||||
$str = "\x88\xa9\xf0\xee\xf1\xea\xee\xf8\xed\xfb\xe9";
|
||||
var_dump($str, htmlentities($str, ENT_QUOTES, ''));
|
||||
var_dump(bin2hex($str), htmlentities($str, ENT_QUOTES, ''));
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
string(11) "ˆ©ðîñêîøíûé"
|
||||
string(22) "88a9f0eef1eaeef8edfbe9"
|
||||
string(75) "€©роскошный"
|
||||
===DONE===
|
||||
|
97
ext/standard/tests/strings/htmlspecialchars_basic.phpt
Normal file
97
ext/standard/tests/strings/htmlspecialchars_basic.phpt
Normal file
@ -0,0 +1,97 @@
|
||||
--TEST--
|
||||
Test htmlspecialchars() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string htmlspecialchars ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )
|
||||
* Description: Convert special characters to HTML entities
|
||||
* Source code: ext/standard/string.c
|
||||
*/
|
||||
|
||||
echo "*** Testing htmlspecialchars() : basic functionality ***\n";
|
||||
|
||||
$s1 = "abc<>\"&\n";
|
||||
$s2 = "&&abc<>\"&\n";
|
||||
$s3 = "a>,\<bc<>\"&\n";
|
||||
$s4 = "a\'\'&bc<>\"&\n";
|
||||
$s5 = "&<\n";
|
||||
echo "Basic tests\n";
|
||||
echo "Test 1: " . htmlspecialchars ($s1);
|
||||
echo "Test 2: " . htmlspecialchars ($s2);
|
||||
echo "Test 3: " . htmlspecialchars ($s3);
|
||||
echo "Test 4: " . htmlspecialchars ($s4);
|
||||
echo "Test 5: " . htmlspecialchars ($s5);
|
||||
echo "Test 6: " . htmlspecialchars ($s1,ENT_NOQUOTES);
|
||||
echo "Test 7: " . htmlspecialchars ($s2,ENT_NOQUOTES);
|
||||
echo "Test 8: " . htmlspecialchars ($s3,ENT_NOQUOTES);
|
||||
echo "Test 9: " . htmlspecialchars ($s4,ENT_NOQUOTES);
|
||||
echo "Test 10: " . htmlspecialchars ($s5,ENT_NOQUOTES);
|
||||
echo "Test 11: " . htmlspecialchars ($s1,ENT_COMPAT);
|
||||
echo "Test 12: " . htmlspecialchars ($s2,ENT_COMPAT);
|
||||
echo "Test 13: " . htmlspecialchars ($s3,ENT_COMPAT);
|
||||
echo "Test 14: " . htmlspecialchars ($s4,ENT_COMPAT);
|
||||
echo "Test 15: " . htmlspecialchars ($s5,ENT_COMPAT);
|
||||
echo "Test 16: " . htmlspecialchars ($s1,ENT_QUOTES);
|
||||
echo "Test 17: " . htmlspecialchars ($s2,ENT_QUOTES);
|
||||
echo "Test 18: " . htmlspecialchars ($s3,ENT_QUOTES);
|
||||
echo "Test 19: " . htmlspecialchars ($s4,ENT_QUOTES);
|
||||
echo "Test 20: " . htmlspecialchars ($s5,ENT_QUOTES);
|
||||
|
||||
echo "\nTry with char set option - specify default ISO-8859-1\n";
|
||||
echo "Test 21: " . htmlspecialchars ($s1,ENT_NOQUOTES, "ISO-8859-1");
|
||||
echo "Test 22: " . htmlspecialchars ($s2,ENT_COMPAT, "ISO-8859-1");
|
||||
echo "Test 23: " . htmlspecialchars ($s3,ENT_QUOTES, "ISO-8859-1");
|
||||
echo "Test 24: " . htmlspecialchars ($s5,ENT_QUOTES, "ISO-8859-1");
|
||||
|
||||
echo "\nTry with double decode FALSE\n";
|
||||
$s1 = ""&xyz>abc"\n";
|
||||
$s2 = ""&123<456"\n";
|
||||
$s3 = "\"300 < 400\"\n";
|
||||
echo "Test 25: " . htmlspecialchars ($s1,ENT_NOQUOTES, "ISO-8859-1", false);
|
||||
echo "Test 26: " . htmlspecialchars ($s2,ENT_NOQUOTES, "ISO-8859-1", false);
|
||||
echo "Test 27: " . htmlspecialchars ($s3,ENT_NOQUOTES, "ISO-8859-1", false);
|
||||
|
||||
echo "\nTry with double decode TRUE\n";
|
||||
echo "Test 28: " . htmlspecialchars ($s1, ENT_NOQUOTES, "ISO-8859-1", true);
|
||||
echo "Test 29: " . htmlspecialchars ($s2, ENT_NOQUOTES, "ISO-8859-1", true);
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
*** Testing htmlspecialchars() : basic functionality ***
|
||||
Basic tests
|
||||
Test 1: abc<>"&
|
||||
Test 2: &&abc<>"&
|
||||
Test 3: a>,\<bc<>"&
|
||||
Test 4: a\'\'&bc<>"&
|
||||
Test 5: &amp;&lt;
|
||||
Test 6: abc<>"&
|
||||
Test 7: &&abc<>"&
|
||||
Test 8: a>,\<bc<>"&
|
||||
Test 9: a\'\'&bc<>"&
|
||||
Test 10: &amp;&lt;
|
||||
Test 11: abc<>"&
|
||||
Test 12: &&abc<>"&
|
||||
Test 13: a>,\<bc<>"&
|
||||
Test 14: a\'\'&bc<>"&
|
||||
Test 15: &amp;&lt;
|
||||
Test 16: abc<>"&
|
||||
Test 17: &&abc<>"&
|
||||
Test 18: a>,\<bc<>"&
|
||||
Test 19: a\'\'&bc<>"&
|
||||
Test 20: &amp;&lt;
|
||||
|
||||
Try with char set option - specify default ISO-8859-1
|
||||
Test 21: abc<>"&
|
||||
Test 22: &&abc<>"&
|
||||
Test 23: a>,\<bc<>"&
|
||||
Test 24: &amp;&lt;
|
||||
|
||||
Try with double decode FALSE
|
||||
Test 25: "&xyz>abc"
|
||||
Test 26: "&123<456"
|
||||
Test 27: "300 < 400"
|
||||
|
||||
Try with double decode TRUE
|
||||
Test 28: &quot;&amp;xyz&gt;abc&quot;
|
||||
Test 29: &quot;&amp;123&lt;456&quot;
|
||||
===DONE===
|
@ -40,8 +40,8 @@ $values = array(
|
||||
// float data
|
||||
10.5,
|
||||
-10.5,
|
||||
10.5e10,
|
||||
10.6E-10,
|
||||
10.1234567e10,
|
||||
10.7654321E-10,
|
||||
.5,
|
||||
|
||||
// array data
|
||||
@ -89,8 +89,8 @@ foreach($values as $value) {
|
||||
// close the file resource used
|
||||
fclose($file_handle);
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing htmlspecialchars_decode() : usage variations ***
|
||||
-- Iterator 1 --
|
||||
@ -106,9 +106,9 @@ string(4) "10.5"
|
||||
-- Iterator 6 --
|
||||
string(5) "-10.5"
|
||||
-- Iterator 7 --
|
||||
string(12) "105000000000"
|
||||
string(12) "101234567000"
|
||||
-- Iterator 8 --
|
||||
string(7) "1.06E-9"
|
||||
string(13) "1.07654321E-9"
|
||||
-- Iterator 9 --
|
||||
string(3) "0.5"
|
||||
-- Iterator 10 --
|
||||
@ -157,4 +157,5 @@ string(0) ""
|
||||
|
||||
Warning: htmlspecialchars_decode() expects parameter 1 to be string, resource given in %s on line %d
|
||||
NULL
|
||||
Done
|
||||
===DONE===
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user