mirror of
https://github.com/php/php-src.git
synced 2024-10-19 23:44:13 +00:00
334 lines
9.3 KiB
Plaintext
334 lines
9.3 KiB
Plaintext
|
--TEST--
|
|||
|
Test stripslashes() function : usage variations - un-quote strings quoted with addslashes()
|
|||
|
--FILE--
|
|||
|
<?php
|
|||
|
/* Prototype : string stripslashes ( string $str )
|
|||
|
* Description: Returns an un-quoted string
|
|||
|
* Source code: ext/standard/string.c
|
|||
|
*/
|
|||
|
|
|||
|
/*
|
|||
|
* Test stripslashes() with various strings containing characters thats can be backslashed.
|
|||
|
* First adding slashes using addslashes() and then removing the slashes using stripslashes()
|
|||
|
*/
|
|||
|
|
|||
|
echo "*** Testing stripslashes() : with various strings containing backslashed characters ***\n";
|
|||
|
|
|||
|
// initialising a heredoc string
|
|||
|
$heredoc_string = <<<EOT
|
|||
|
This is line 1 of 'heredoc' string
|
|||
|
This is line 2 of "heredoc" string
|
|||
|
EOT;
|
|||
|
|
|||
|
$heredoc_null_string =<<<EOT
|
|||
|
EOT;
|
|||
|
$heredoc_string_only_backslash =<<<EOT
|
|||
|
\
|
|||
|
EOT;
|
|||
|
$heredoc_string_only_single_quote =<<<EOT
|
|||
|
'
|
|||
|
EOT;
|
|||
|
$heredoc_string_only_double_quote =<<<EOT
|
|||
|
"
|
|||
|
EOT;
|
|||
|
|
|||
|
// initialising the string array
|
|||
|
|
|||
|
$str_array = array(
|
|||
|
// string without any characters that can be backslashed
|
|||
|
'Hello world',
|
|||
|
|
|||
|
// string with single quotes
|
|||
|
"how're you doing?",
|
|||
|
"don't disturb u'r neighbours",
|
|||
|
"don't disturb u'r neighbours''",
|
|||
|
'',
|
|||
|
'\'',
|
|||
|
"'",
|
|||
|
$heredoc_string_only_single_quote,
|
|||
|
|
|||
|
// string with double quotes
|
|||
|
'he said, "he will be on leave"',
|
|||
|
'he said, ""he will be on leave"',
|
|||
|
'"""PHP"""',
|
|||
|
"",
|
|||
|
"\"",
|
|||
|
'"',
|
|||
|
"hello\"",
|
|||
|
$heredoc_string_only_double_quote,
|
|||
|
|
|||
|
// string with backslash characters
|
|||
|
'Is your name Ram\Krishna?',
|
|||
|
'\\0.0.0.0',
|
|||
|
'c:\php\testcase\stripslashes',
|
|||
|
'\\',
|
|||
|
$heredoc_string_only_backslash,
|
|||
|
|
|||
|
// string with nul characters
|
|||
|
'hello'.chr(0).'world',
|
|||
|
chr(0).'hello'.chr(0),
|
|||
|
chr(0).chr(0).'hello',
|
|||
|
chr(0),
|
|||
|
|
|||
|
// mixed strings
|
|||
|
"'\\0.0.0.0'",
|
|||
|
"'\\0.0.0.0'".chr(0),
|
|||
|
chr(0)."'c:\php\'",
|
|||
|
'"\\0.0.0.0"',
|
|||
|
'"c:\php\"'.chr(0)."'",
|
|||
|
'"hello"'."'world'".chr(0).'//',
|
|||
|
|
|||
|
// string with hexadecimal number
|
|||
|
"0xABCDEF0123456789",
|
|||
|
"\x00",
|
|||
|
'!@#$%&*@$%#&/;:,<>',
|
|||
|
"hello\x00world",
|
|||
|
|
|||
|
// heredoc strings
|
|||
|
$heredoc_string,
|
|||
|
$heredoc_null_string
|
|||
|
);
|
|||
|
|
|||
|
$count = 1;
|
|||
|
// looping to test for all strings in $str_array
|
|||
|
foreach( $str_array as $str ) {
|
|||
|
echo "\n-- Iteration $count --\n";
|
|||
|
$str_addslashes = addslashes($str);
|
|||
|
var_dump("The string after addslashes is:", $str_addslashes);
|
|||
|
$str_stripslashes = stripslashes($str_addslashes);
|
|||
|
var_dump("The string after stripslashes is:", $str_stripslashes);
|
|||
|
if( strcmp($str, $str_stripslashes) != 0 )
|
|||
|
echo "\nError: Original string and string from stripslash() donot match\n";
|
|||
|
$count ++;
|
|||
|
}
|
|||
|
|
|||
|
echo "Done\n";
|
|||
|
?>
|
|||
|
--EXPECTF--
|
|||
|
*** Testing stripslashes() : with various strings containing backslashed characters ***
|
|||
|
|
|||
|
-- Iteration 1 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(11) "Hello world"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(11) "Hello world"
|
|||
|
|
|||
|
-- Iteration 2 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(18) "how\'re you doing?"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(17) "how're you doing?"
|
|||
|
|
|||
|
-- Iteration 3 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(30) "don\'t disturb u\'r neighbours"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(28) "don't disturb u'r neighbours"
|
|||
|
|
|||
|
-- Iteration 4 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(34) "don\'t disturb u\'r neighbours\'\'"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(30) "don't disturb u'r neighbours''"
|
|||
|
|
|||
|
-- Iteration 5 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(0) ""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(0) ""
|
|||
|
|
|||
|
-- Iteration 6 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\'"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) "'"
|
|||
|
|
|||
|
-- Iteration 7 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\'"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) "'"
|
|||
|
|
|||
|
-- Iteration 8 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\'"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) "'"
|
|||
|
|
|||
|
-- Iteration 9 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(32) "he said, \"he will be on leave\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(30) "he said, "he will be on leave""
|
|||
|
|
|||
|
-- Iteration 10 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(34) "he said, \"\"he will be on leave\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(31) "he said, ""he will be on leave""
|
|||
|
|
|||
|
-- Iteration 11 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(15) "\"\"\"PHP\"\"\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(9) """"PHP""""
|
|||
|
|
|||
|
-- Iteration 12 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(0) ""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(0) ""
|
|||
|
|
|||
|
-- Iteration 13 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) """
|
|||
|
|
|||
|
-- Iteration 14 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) """
|
|||
|
|
|||
|
-- Iteration 15 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(7) "hello\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(6) "hello""
|
|||
|
|
|||
|
-- Iteration 16 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\""
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) """
|
|||
|
|
|||
|
-- Iteration 17 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(26) "Is your name Ram\\Krishna?"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(25) "Is your name Ram\Krishna?"
|
|||
|
|
|||
|
-- Iteration 18 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(9) "\\0.0.0.0"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(8) "\0.0.0.0"
|
|||
|
|
|||
|
-- Iteration 19 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(31) "c:\\php\\testcase\\stripslashes"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(28) "c:\php\testcase\stripslashes"
|
|||
|
|
|||
|
-- Iteration 20 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\\"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) "\"
|
|||
|
|
|||
|
-- Iteration 21 --
|
|||
|
string(31) "The string after addslashes is:"
|
|||
|
string(2) "\0"
|
|||
|
string(33) "The string after stripslashes is:"
|
|||
|
string(1) " |