PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/standard/tests/strings/stripslashes_variation5.phpt

http://github.com/infusion/PHP
Unknown | 202 lines | 169 code | 33 blank | 0 comment | 0 complexity | 0194657453696c4e53607952001c761d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. --TEST--
  2. Test stripslashes() function : usage variations - with magic_quotes_sybase directive ON
  3. --FILE--
  4. <?php
  5. /* Prototype : string stripslashes ( string $str )
  6. * Description: Returns an un-quoted string
  7. * Source code: ext/standard/string.c
  8. */
  9. /*
  10. * Test stripslashes() with PHP directive magic_quotes_sybase set ON
  11. */
  12. echo "*** Testing stripslashes() : with php directive magic_quotes_sybase set ON ***\n";
  13. // setting ON the php directive magic_quotes_sybase
  14. ini_set("magic_quotes_sybase", "1");
  15. // initialising a heredoc string
  16. $heredoc_string = <<<EOT
  17. This is line 1 of 'heredoc' string
  18. This is line 2 of "heredoc" string
  19. EOT;
  20. $heredoc_null_string =<<<EOT
  21. EOT;
  22. // initialising the string array
  23. $str_array = array(
  24. // string without any characters that can be backslashed
  25. 'Hello world',
  26. // string with single quotes
  27. "how're you doing?",
  28. "don't disturb u'r neighbours",
  29. "don't disturb u'r neighbours''",
  30. '',
  31. '\'',
  32. "'",
  33. // string with double quotes
  34. 'he said, "he will be on leave"',
  35. 'he said, ""he will be on leave"',
  36. '"""PHP"""',
  37. "",
  38. "\"",
  39. '"',
  40. "hello\"",
  41. // string with backslash characters
  42. 'Is your name Ram\Krishna?',
  43. 'c:\php\testcase\stripslashes',
  44. '\\',
  45. // string with nul characters
  46. 'hello'.chr(0).'world',
  47. chr(0).'hello'.chr(0),
  48. chr(0).chr(0).'hello',
  49. chr(0),
  50. // mixed strings
  51. "\\\"'0.0.0.0'",
  52. "\\\"'0.0.0.0'".chr(0),
  53. chr(0)."'c:\php\'",
  54. '"c:\php\"'.chr(0)."'",
  55. '"hello"'."'world'".chr(0).'//',
  56. // string with hexadecimal number
  57. "0xABCDEF0123456789",
  58. "\xabcdef0123456789",
  59. '!@#$%&*@$%#&/;:,<>',
  60. "hello\x00world",
  61. // heredoc strings
  62. $heredoc_string,
  63. $heredoc_null_string
  64. );
  65. $count = 1;
  66. // looping to test for all strings in $str_array
  67. foreach( $str_array as $str ) {
  68. echo "\n-- Iteration $count --\n";
  69. $str_addslashes = addslashes($str);
  70. var_dump("The string after addslashes is:", $str_addslashes);
  71. $str_stripslashes = stripslashes($str_addslashes);
  72. var_dump("The string after stripslashes is:", $str_stripslashes);
  73. if( strcmp($str, $str_stripslashes) != 0 )
  74. echo "\nOriginal string and string from stripslashes() donot match\n";
  75. $count ++;
  76. }
  77. echo "Done\n";
  78. ?>
  79. --EXPECTF--
  80. *** Testing stripslashes() : with php directive magic_quotes_sybase set ON ***
  81. -- Iteration 1 --
  82. string(31) "The string after addslashes is:"
  83. string(11) "Hello world"
  84. string(33) "The string after stripslashes is:"
  85. string(11) "Hello world"
  86. -- Iteration 2 --
  87. string(31) "The string after addslashes is:"
  88. string(18) "how''re you doing?"
  89. string(33) "The string after stripslashes is:"
  90. string(17) "how're you doing?"
  91. -- Iteration 3 --
  92. string(31) "The string after addslashes is:"
  93. string(30) "don''t disturb u''r neighbours"
  94. string(33) "The string after stripslashes is:"
  95. string(28) "don't disturb u'r neighbours"
  96. -- Iteration 4 --
  97. string(31) "The string after addslashes is:"
  98. string(34) "don''t disturb u''r neighbours''''"
  99. string(33) "The string after stripslashes is:"
  100. string(30) "don't disturb u'r neighbours''"
  101. -- Iteration 5 --
  102. string(31) "The string after addslashes is:"
  103. string(0) ""
  104. string(33) "The string after stripslashes is:"
  105. string(0) ""
  106. -- Iteration 6 --
  107. string(31) "The string after addslashes is:"
  108. string(2) "''"
  109. string(33) "The string after stripslashes is:"
  110. string(1) "'"
  111. -- Iteration 7 --
  112. string(31) "The string after addslashes is:"
  113. string(2) "''"
  114. string(33) "The string after stripslashes is:"
  115. string(1) "'"
  116. -- Iteration 8 --
  117. string(31) "The string after addslashes is:"
  118. string(30) "he said, "he will be on leave""
  119. string(33) "The string after stripslashes is:"
  120. string(30) "he said, "he will be on leave""
  121. -- Iteration 9 --
  122. string(31) "The string after addslashes is:"
  123. string(31) "he said, ""he will be on leave""
  124. string(33) "The string after stripslashes is:"
  125. string(31) "he said, ""he will be on leave""
  126. -- Iteration 10 --
  127. string(31) "The string after addslashes is:"
  128. string(9) """"PHP""""
  129. string(33) "The string after stripslashes is:"
  130. string(9) """"PHP""""
  131. -- Iteration 11 --
  132. string(31) "The string after addslashes is:"
  133. string(0) ""
  134. string(33) "The string after stripslashes is:"
  135. string(0) ""
  136. -- Iteration 12 --
  137. string(31) "The string after addslashes is:"
  138. string(1) """
  139. string(33) "The string after stripslashes is:"
  140. string(1) """
  141. -- Iteration 13 --
  142. string(31) "The string after addslashes is:"
  143. string(1) """
  144. string(33) "The string after stripslashes is:"
  145. string(1) """
  146. -- Iteration 14 --
  147. string(31) "The string after addslashes is:"
  148. string(6) "hello""
  149. string(33) "The string after stripslashes is:"
  150. string(6) "hello""
  151. -- Iteration 15 --
  152. string(31) "The string after addslashes is:"
  153. string(25) "Is your name Ram\Krishna?"
  154. string(33) "The string after stripslashes is:"
  155. string(25) "Is your name Ram\Krishna?"
  156. -- Iteration 16 --
  157. string(31) "The string after addslashes is:"
  158. string(28) "c:\php\testcase\stripslashes"
  159. string(33) "The string after stripslashes is:"
  160. string(28) "c:\php\testcase\stripslashes"
  161. -- Iteration 17 --
  162. string(31) "The string after addslashes is:"
  163. string(1) "\"
  164. string(33) "The string after stripslashes is:"
  165. string(1) "\"
  166. -- Iteration 18 --
  167. string(31) "The string after addslashes is:"
  168. string(12) "hello\0world"
  169. string(33) "The string after stripslashes is:"
  170. string(11) "hello�world"
  171. -- Iteration 19 --
  172. string(31) "The string after addslashes is:"
  173. string(9) "\0hello\0"
  174. string(33) "The string after stripslashes is:"
  175. string(7) "�hello�"
  176. -- Iteration 20 --
  177. string(31) "The string after addslashes is:"
  178. string(9) "\0\0hello"
  179. string(33) "The string after stripslashes is:"
  180. string(7) "��hello"
  181. -- Iteration 21 --
  182. string(31) "The string after addslashes is:"
  183. string(2) "\0"
  184. string(33) "The string after stripslashes is:"
  185. string(1) "�"
  186. -- Iteration 22 --
  187. string(31) "The string after addslashes is:"
  188. string(13) "\"''0.0.0.0''"
  189. string(33) "The string after stripslashes is:"
  190. string(11) "\"'0.0.0.0'"
  191. -- Iteration 23 --
  192. string(31) "The string after addslashes is:"
  193. string(15) "\"''0.0.0.0''\0"
  194. string(33) "The string after stripslashes is:"
  195. string(12) "\"'0.0.0.0'�"
  196. -- Iteration 24 --
  197. string(31) "The string after addslashes is:"
  198. string(13) "\0''c:\php\''"
  199. string(33) "The string after stripslashes is:"
  200. string(10) "�'c:\php\'"
  201. -- Iteration 25 --
  202. string(31) "The string after addslashes is:"
  203. string(13) ""c:\php\"\0''"
  204. string(33) "The string after stripslashes is:"
  205. string(11) ""c:\php\"�'"
  206. -- Iteration 26 --
  207. string(31) "The string after addslashes is:"
  208. string(20) ""hello"''world''\0//"
  209. string(33) "The string after stripslashes is:"
  210. string(17) ""hello"'world'�//"
  211. -- Iteration 27 --
  212. string(31) "The string after addslashes is:"
  213. string(18) "0xABCDEF0123456789"
  214. string(33) "The string after stripslashes is:"
  215. string(18) "0xABCDEF0123456789"
  216. -- Iteration 28 --
  217. string(31) "The string after addslashes is:"
  218. string(15) "Ťcdef0123456789"
  219. string(33) "The string after stripslashes is:"
  220. string(15) "Ťcdef0123456789"
  221. -- Iteration 29 --
  222. string(31) "The string after addslashes is:"
  223. string(18) "!@#$%&*@$%#&/;:,<>"
  224. string(33) "The string after stripslashes is:"
  225. string(18) "!@#$%&*@$%#&/;:,<>"
  226. -- Iteration 30 --
  227. string(31) "The string after addslashes is:"
  228. string(12) "hello\0world"
  229. string(33) "The string after stripslashes is:"
  230. string(11) "hello�world"
  231. -- Iteration 31 --
  232. string(31) "The string after addslashes is:"
  233. string(71) "This is line 1 of ''heredoc'' string
  234. This is line 2 of "heredoc" string"
  235. string(33) "The string after stripslashes is:"
  236. string(69) "This is line 1 of 'heredoc' string
  237. This is line 2 of "heredoc" string"
  238. -- Iteration 32 --
  239. string(31) "The string after addslashes is:"
  240. string(0) ""
  241. string(33) "The string after stripslashes is:"
  242. string(0) ""
  243. Done