addslashes_variation2.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. --TEST--
  2. Test addslashes() function : usage variations - strings with characters to be backslashed
  3. --FILE--
  4. <?php
  5. /*
  6. * Test addslashes() with various strings containing characters that can be backslashed
  7. */
  8. echo "*** Testing addslashes() : with various strings containing characters to be backslashed ***\n";
  9. // initialising a heredoc string
  10. $heredoc_string = <<<EOT
  11. This is line 1 of 'heredoc' string
  12. This is line 2 of "heredoc" string
  13. EOT;
  14. $heredoc_null_string =<<<EOT
  15. EOT;
  16. // initialising the string array
  17. $str_array = array(
  18. // string without any characters that can be backslashed
  19. 'Hello world',
  20. // string with single quotes
  21. "how're you doing?",
  22. "don't disturb u'r neighbours",
  23. "don't disturb u'r neighbours''",
  24. '',
  25. '\'',
  26. "'",
  27. // string with double quotes
  28. 'he said, "he will be on leave"',
  29. 'he said, ""he will be on leave"',
  30. '"""PHP"""',
  31. "",
  32. "\"",
  33. '"',
  34. "hello\"",
  35. // string with backslash characters
  36. 'Is your name Ram\Krishna?',
  37. '\\0.0.0.0',
  38. 'c:\php\testcase\addslashes',
  39. '\\',
  40. // string with nul characters
  41. 'hello'.chr(0).'world',
  42. chr(0).'hello'.chr(0),
  43. chr(0).chr(0).'hello',
  44. chr(0),
  45. // mixed strings
  46. "'\\0.0.0.0'",
  47. "'\\0.0.0.0'".chr(0),
  48. chr(0)."'c:\php\'",
  49. '"\\0.0.0.0"',
  50. '"c:\php\"'.chr(0)."'",
  51. '"hello"'."'world'".chr(0).'//',
  52. // string with hexadecimal number
  53. "0xABCDEF0123456789",
  54. "\x00",
  55. '!@#$%&*@$%#&/;:,<>',
  56. "hello\x00world",
  57. // heredoc strings
  58. $heredoc_string,
  59. $heredoc_null_string
  60. );
  61. $count = 1;
  62. // looping to test for all strings in $str_array
  63. foreach( $str_array as $str ) {
  64. echo "\n-- Iteration $count --\n";
  65. var_dump( addslashes($str) );
  66. $count ++;
  67. }
  68. echo "Done\n";
  69. ?>
  70. --EXPECTF--
  71. *** Testing addslashes() : with various strings containing characters to be backslashed ***
  72. -- Iteration 1 --
  73. string(11) "Hello world"
  74. -- Iteration 2 --
  75. string(18) "how\'re you doing?"
  76. -- Iteration 3 --
  77. string(30) "don\'t disturb u\'r neighbours"
  78. -- Iteration 4 --
  79. string(34) "don\'t disturb u\'r neighbours\'\'"
  80. -- Iteration 5 --
  81. string(0) ""
  82. -- Iteration 6 --
  83. string(2) "\'"
  84. -- Iteration 7 --
  85. string(2) "\'"
  86. -- Iteration 8 --
  87. string(32) "he said, \"he will be on leave\""
  88. -- Iteration 9 --
  89. string(34) "he said, \"\"he will be on leave\""
  90. -- Iteration 10 --
  91. string(15) "\"\"\"PHP\"\"\""
  92. -- Iteration 11 --
  93. string(0) ""
  94. -- Iteration 12 --
  95. string(2) "\""
  96. -- Iteration 13 --
  97. string(2) "\""
  98. -- Iteration 14 --
  99. string(7) "hello\""
  100. -- Iteration 15 --
  101. string(26) "Is your name Ram\\Krishna?"
  102. -- Iteration 16 --
  103. string(9) "\\0.0.0.0"
  104. -- Iteration 17 --
  105. string(29) "c:\\php\\testcase\\addslashes"
  106. -- Iteration 18 --
  107. string(2) "\\"
  108. -- Iteration 19 --
  109. string(12) "hello\0world"
  110. -- Iteration 20 --
  111. string(9) "\0hello\0"
  112. -- Iteration 21 --
  113. string(9) "\0\0hello"
  114. -- Iteration 22 --
  115. string(2) "\0"
  116. -- Iteration 23 --
  117. string(13) "\'\\0.0.0.0\'"
  118. -- Iteration 24 --
  119. string(15) "\'\\0.0.0.0\'\0"
  120. -- Iteration 25 --
  121. string(15) "\0\'c:\\php\\\'"
  122. -- Iteration 26 --
  123. string(13) "\"\\0.0.0.0\""
  124. -- Iteration 27 --
  125. string(17) "\"c:\\php\\\"\0\'"
  126. -- Iteration 28 --
  127. string(22) "\"hello\"\'world\'\0//"
  128. -- Iteration 29 --
  129. string(18) "0xABCDEF0123456789"
  130. -- Iteration 30 --
  131. string(2) "\0"
  132. -- Iteration 31 --
  133. string(18) "!@#$%&*@$%#&/;:,<>"
  134. -- Iteration 32 --
  135. string(12) "hello\0world"
  136. -- Iteration 33 --
  137. string(7%d) "This is line 1 of \'heredoc\' string
  138. This is line 2 of \"heredoc\" string"
  139. -- Iteration 34 --
  140. string(0) ""
  141. Done