Annotation of embedaddon/php/ext/standard/tests/strings/addslashes_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test addslashes() function : usage variations - strings with characters to be backslashed
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : string addslashes ( string $str )
                      6:  * Description: Returns a string with backslashes before characters that need to be quoted in database queries etc.
                      7:  * Source code: ext/standard/string.c
                      8: */
                      9: 
                     10: /*
                     11:  * Test addslashes() with various strings containing characters thats can be backslashed 
                     12: */
                     13: 
                     14: echo "*** Testing addslashes() : with various strings containing characters to be backslashed ***\n";
                     15: 
                     16: // initialising a heredoc string
                     17: $heredoc_string = <<<EOT
                     18: This is line 1 of 'heredoc' string
                     19: This is line 2 of "heredoc" string
                     20: EOT;
                     21: 
                     22: $heredoc_null_string =<<<EOT
                     23: EOT;
                     24:  
                     25: // initialising the string array
                     26: 
                     27: $str_array = array( 
                     28:                     // string without any characters that can be backslashed
                     29:                     'Hello world',
                     30:  
                     31:                     // string with single quotes
                     32:                     "how're you doing?", 
                     33:                     "don't disturb u'r neighbours",
                     34:                     "don't disturb u'r neighbours''",
                     35:                     '',
                     36:                     '\'',
                     37:                     "'",
                     38:                     
                     39:                     // string with double quotes
                     40:                     'he said, "he will be on leave"',
                     41:                     'he said, ""he will be on leave"',
                     42:                     '"""PHP"""',
                     43:                     "",
                     44:                     "\"",
                     45:                     '"',
                     46:                    "hello\"",
                     47:                          
                     48:                     // string with backslash characters
                     49:                     'Is your name Ram\Krishna?',
                     50:                     '\\0.0.0.0',
                     51:                     'c:\php\testcase\addslashes',
                     52:                     '\\',
                     53: 
                     54:                     // string with nul characters
                     55:                     'hello'.chr(0).'world',
                     56:                     chr(0).'hello'.chr(0),
                     57:                     chr(0).chr(0).'hello',
                     58:                     chr(0),
                     59: 
                     60:                     // mixed strings
                     61:                     "'\\0.0.0.0'",
                     62:                     "'\\0.0.0.0'".chr(0),
                     63:                     chr(0)."'c:\php\'",
                     64:                     '"\\0.0.0.0"',
                     65:                     '"c:\php\"'.chr(0)."'",
                     66:                     '"hello"'."'world'".chr(0).'//',
                     67: 
                     68:                    // string with hexadecimal number
                     69:                     "0xABCDEF0123456789",
                     70:                     "\x00",
                     71:                     '!@#$%&*@$%#&/;:,<>',
                     72:                     "hello\x00world",
                     73: 
                     74:                     // heredoc strings
                     75:                     $heredoc_string,
                     76:                     $heredoc_null_string
                     77:                   );
                     78: 
                     79: $count = 1;
                     80: // looping to test for all strings in $str_array
                     81: foreach( $str_array as $str )  {
                     82:   echo "\n-- Iteration $count --\n";
                     83:   var_dump( addslashes($str) );
                     84:   $count ++;
                     85: }
                     86: 
                     87: echo "Done\n";
                     88: ?>
                     89: --EXPECTF--
                     90: *** Testing addslashes() : with various strings containing characters to be backslashed ***
                     91: 
                     92: -- Iteration 1 --
                     93: string(11) "Hello world"
                     94: 
                     95: -- Iteration 2 --
                     96: string(18) "how\'re you doing?"
                     97: 
                     98: -- Iteration 3 --
                     99: string(30) "don\'t disturb u\'r neighbours"
                    100: 
                    101: -- Iteration 4 --
                    102: string(34) "don\'t disturb u\'r neighbours\'\'"
                    103: 
                    104: -- Iteration 5 --
                    105: string(0) ""
                    106: 
                    107: -- Iteration 6 --
                    108: string(2) "\'"
                    109: 
                    110: -- Iteration 7 --
                    111: string(2) "\'"
                    112: 
                    113: -- Iteration 8 --
                    114: string(32) "he said, \"he will be on leave\""
                    115: 
                    116: -- Iteration 9 --
                    117: string(34) "he said, \"\"he will be on leave\""
                    118: 
                    119: -- Iteration 10 --
                    120: string(15) "\"\"\"PHP\"\"\""
                    121: 
                    122: -- Iteration 11 --
                    123: string(0) ""
                    124: 
                    125: -- Iteration 12 --
                    126: string(2) "\""
                    127: 
                    128: -- Iteration 13 --
                    129: string(2) "\""
                    130: 
                    131: -- Iteration 14 --
                    132: string(7) "hello\""
                    133: 
                    134: -- Iteration 15 --
                    135: string(26) "Is your name Ram\\Krishna?"
                    136: 
                    137: -- Iteration 16 --
                    138: string(9) "\\0.0.0.0"
                    139: 
                    140: -- Iteration 17 --
                    141: string(29) "c:\\php\\testcase\\addslashes"
                    142: 
                    143: -- Iteration 18 --
                    144: string(2) "\\"
                    145: 
                    146: -- Iteration 19 --
                    147: string(12) "hello\0world"
                    148: 
                    149: -- Iteration 20 --
                    150: string(9) "\0hello\0"
                    151: 
                    152: -- Iteration 21 --
                    153: string(9) "\0\0hello"
                    154: 
                    155: -- Iteration 22 --
                    156: string(2) "\0"
                    157: 
                    158: -- Iteration 23 --
                    159: string(13) "\'\\0.0.0.0\'"
                    160: 
                    161: -- Iteration 24 --
                    162: string(15) "\'\\0.0.0.0\'\0"
                    163: 
                    164: -- Iteration 25 --
                    165: string(15) "\0\'c:\\php\\\'"
                    166: 
                    167: -- Iteration 26 --
                    168: string(13) "\"\\0.0.0.0\""
                    169: 
                    170: -- Iteration 27 --
                    171: string(17) "\"c:\\php\\\"\0\'"
                    172: 
                    173: -- Iteration 28 --
                    174: string(22) "\"hello\"\'world\'\0//"
                    175: 
                    176: -- Iteration 29 --
                    177: string(18) "0xABCDEF0123456789"
                    178: 
                    179: -- Iteration 30 --
                    180: string(2) "\0"
                    181: 
                    182: -- Iteration 31 --
                    183: string(18) "!@#$%&*@$%#&/;:,<>"
                    184: 
                    185: -- Iteration 32 --
                    186: string(12) "hello\0world"
                    187: 
                    188: -- Iteration 33 --
                    189: string(73) "This is line 1 of \'heredoc\' string
                    190: This is line 2 of \"heredoc\" string"
                    191: 
                    192: -- Iteration 34 --
                    193: string(0) ""
                    194: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>