mirror of
https://github.com/php/php-src.git
synced 2024-09-28 05:16:12 +00:00
174 lines
4.4 KiB
PHP
174 lines
4.4 KiB
PHP
--TEST--
|
||
Test addcslashes() function
|
||
--INI--
|
||
precision=14
|
||
--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 = b"goodyear12345NULL\0truefalse\a\v\f\b\n\r\t";
|
||
$charlist = array (
|
||
NULL,
|
||
2,
|
||
array(5,6,7),
|
||
b"a",
|
||
b"\0",
|
||
b"\n",
|
||
b"\r",
|
||
b"\t",
|
||
b"\a",
|
||
b"\v",
|
||
b"\b",
|
||
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, b"\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"b") );
|
||
|
||
/* Miscelleneous input */
|
||
echo "\n*** Testing addcslashes() with miscelleneous input arguments ***\n";
|
||
var_dump( addcslashes(b"", b"") );
|
||
var_dump( addcslashes(b"", b"burp") );
|
||
var_dump( addcslashes(b"kaboemkara!", b"") );
|
||
var_dump( addcslashes(b"foobarbaz", b'bar') );
|
||
var_dump( addcslashes(b'foo[ ]', b'A..z') );
|
||
var_dump( @addcslashes(b"zoo['.']", b'z..A') );
|
||
var_dump( addcslashes(b'abcdefghijklmnopqrstuvwxyz', b"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( b"\0" , 0 ) );
|
||
var_dump( addcslashes( NULL, NULL) );
|
||
var_dump( addcslashes( -1.234578, 3 ) );
|
||
var_dump( addcslashes( b" ", b" ") );
|
||
var_dump( addcslashes( b"string\x00with\x00NULL", b"\0") );
|
||
|
||
echo "\n*** Testing error conditions ***\n";
|
||
/* zero argument */
|
||
var_dump( addcslashes() );
|
||
|
||
/* unexpected arguments */
|
||
var_dump( addcslashes(b"foo[]") );
|
||
var_dump( addcslashes(b'foo[]', b"o", b"foo") );
|
||
|
||
echo "Done\n";
|
||
|
||
?>
|
||
--EXPECTF--
|
||
*** Testing addcslashes() for basic operations ***
|
||
-- Iteration 1 --
|
||
|
||
Warning: addcslashes() expects parameter 2 to be strictly a binary string, null given in %s on line %d
|
||
NULL
|
||
-- Iteration 2 --
|
||
string(39) "goodyear1\2345NULL |