mirror of
https://github.com/php/php-src.git
synced 2024-10-19 07:22:40 +00:00
168 lines
4.0 KiB
Plaintext
168 lines
4.0 KiB
Plaintext
|
--TEST--
|
|||
|
Test addcslashes() function
|
|||
|
--FILE--
|
|||
|
<?php
|
|||
|
/* Prototype: string addcslashes ( string $str, string $charlist );
|
|||
|
Description: Quote string with slashes in a C style.
|
|||
|
Returns a string with backslashes before characters that
|
|||
|
are listed in charlist parameter.
|
|||
|
*/
|
|||
|
|
|||
|
echo "*** Testing addcslashes() for basic operations ***\n";
|
|||
|
/* checking normal operation of addcslashes */
|
|||
|
$string = "goodyear12345NULL\0truefalse\a\v\f\b\n\r\t";
|
|||
|
$charlist = array (
|
|||
|
NULL,
|
|||
|
2,
|
|||
|
array(5,6,7),
|
|||
|
"a",
|
|||
|
"\0",
|
|||
|
"\n",
|
|||
|
"\r",
|
|||
|
"\t",
|
|||
|
"\a",
|
|||
|
"\v",
|
|||
|
"\b",
|
|||
|
"\f"
|
|||
|
);
|
|||
|
/* loop prints string with backslashes before characters
|
|||
|
mentioned in $char using addcslashes() */
|
|||
|
$counter = 1;
|
|||
|
foreach($charlist as $char) {
|
|||
|
echo "-- Iteration $counter --\n";
|
|||
|
var_dump( addcslashes($string, $char) );
|
|||
|
$counter++;
|
|||
|
}
|
|||
|
|
|||
|
/* charlist "\0..\37" would escape all characters with ASCII code between 0 and 31 */
|
|||
|
echo "\n*** Testing addcslashes() with ASCII code between 0 and 31 ***\n";
|
|||
|
var_dump( addcslashes($string, "\0..\37") );
|
|||
|
|
|||
|
/* Checking OBJECTS type */
|
|||
|
echo "\n*** Testing addcslashes() with objects ***\n";
|
|||
|
class string1
|
|||
|
{
|
|||
|
public function __toString() {
|
|||
|
return "Object";
|
|||
|
}
|
|||
|
}
|
|||
|
$obj = new string1;
|
|||
|
var_dump( addcslashes($obj, "b") );
|
|||
|
|
|||
|
/* Miscelleneous input */
|
|||
|
echo "\n*** Testing addcslashes() with miscelleneous input arguments ***\n";
|
|||
|
var_dump( addcslashes("", "") );
|
|||
|
var_dump( addcslashes("", "burp") );
|
|||
|
var_dump( addcslashes("kaboemkara!", "") );
|
|||
|
var_dump( addcslashes("foobarbaz", 'bar') );
|
|||
|
var_dump( addcslashes('foo[ ]', 'A..z') );
|
|||
|
var_dump( @addcslashes("zoo['.']", 'z..A') );
|
|||
|
var_dump( addcslashes('abcdefghijklmnopqrstuvwxyz', "a\145..\160z") );
|
|||
|
var_dump( addcslashes( 123, 123 ) );
|
|||
|
var_dump( addcslashes( 123, NULL) );
|
|||
|
var_dump( addcslashes( NULL, 123) );
|
|||
|
var_dump( addcslashes( 0, 0 ) );
|
|||
|
var_dump( addcslashes( "\0" , 0 ) );
|
|||
|
var_dump( addcslashes( NULL, NULL) );
|
|||
|
var_dump( addcslashes( -1.234578, 3 ) );
|
|||
|
var_dump( addcslashes( " ", " ") );
|
|||
|
var_dump( addcslashes( "string\x00with\x00NULL", "\0") );
|
|||
|
|
|||
|
echo "\n*** Testing error conditions ***\n";
|
|||
|
/* zero argument */
|
|||
|
var_dump( addcslashes() );
|
|||
|
|
|||
|
/* unexpected arguments */
|
|||
|
var_dump( addcslashes("foo[]") );
|
|||
|
var_dump( addcslashes('foo[]', "o", "foo") );
|
|||
|
|
|||
|
echo "Done\n";
|
|||
|
|
|||
|
?>
|
|||
|
--EXPECTF--
|
|||
|
*** Testing addcslashes() for basic operations ***
|
|||
|
-- Iteration 1 --
|
|||
|
string(38) "goodyear12345NULL |