PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/ext/standard/tests/strings/stripslashes_variation2.phpt

http://github.com/infusion/PHP
Unknown | 239 lines | 202 code | 37 blank | 0 comment | 0 complexity | 402ed23fc3aa398bd27cc8e9c0248989 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 - un-quote strings quoted with addslashes()
  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 various strings containing characters thats can be backslashed.
  11. * First adding slashes using addslashes() and then removing the slashes using stripslashes()
  12. */
  13. echo "*** Testing stripslashes() : with various strings containing backslashed characters ***\n";
  14. // initialising a heredoc string
  15. $heredoc_string = <<<EOT
  16. This is line 1 of 'heredoc' string
  17. This is line 2 of "heredoc" string
  18. EOT;
  19. $heredoc_null_string =<<<EOT
  20. EOT;
  21. $heredoc_string_only_backslash =<<<EOT
  22. \
  23. EOT;
  24. $heredoc_string_only_single_quote =<<<EOT
  25. '
  26. EOT;
  27. $heredoc_string_only_double_quote =<<<EOT
  28. "
  29. EOT;
  30. // initialising the string array
  31. $str_array = array(
  32. // string without any characters that can be backslashed
  33. 'Hello world',
  34. // string with single quotes
  35. "how're you doing?",
  36. "don't disturb u'r neighbours",
  37. "don't disturb u'r neighbours''",
  38. '',
  39. '\'',
  40. "'",
  41. $heredoc_string_only_single_quote,
  42. // string with double quotes
  43. 'he said, "he will be on leave"',
  44. 'he said, ""he will be on leave"',
  45. '"""PHP"""',
  46. "",
  47. "\"",
  48. '"',
  49. "hello\"",
  50. $heredoc_string_only_double_quote,
  51. // string with backslash characters
  52. 'Is your name Ram\Krishna?',
  53. '\\0.0.0.0',
  54. 'c:\php\testcase\stripslashes',
  55. '\\',
  56. $heredoc_string_only_backslash,
  57. // string with nul characters
  58. 'hello'.chr(0).'world',
  59. chr(0).'hello'.chr(0),
  60. chr(0).chr(0).'hello',
  61. chr(0),
  62. // mixed strings
  63. "'\\0.0.0.0'",
  64. "'\\0.0.0.0'".chr(0),
  65. chr(0)."'c:\php\'",
  66. '"\\0.0.0.0"',
  67. '"c:\php\"'.chr(0)."'",
  68. '"hello"'."'world'".chr(0).'//',
  69. // string with hexadecimal number
  70. "0xABCDEF0123456789",
  71. "\x00",
  72. '!@#$%&*@$%#&/;:,<>',
  73. "hello\x00world",
  74. // heredoc strings
  75. $heredoc_string,
  76. $heredoc_null_string
  77. );
  78. $count = 1;
  79. // looping to test for all strings in $str_array
  80. foreach( $str_array as $str ) {
  81. echo "\n-- Iteration $count --\n";
  82. $str_addslashes = addslashes($str);
  83. var_dump("The string after addslashes is:", $str_addslashes);
  84. $str_stripslashes = stripslashes($str_addslashes);
  85. var_dump("The string after stripslashes is:", $str_stripslashes);
  86. if( strcmp($str, $str_stripslashes) != 0 )
  87. echo "\nError: Original string and string from stripslash() donot match\n";
  88. $count ++;
  89. }
  90. echo "Done\n";
  91. ?>
  92. --EXPECTF--
  93. *** Testing stripslashes() : with various strings containing backslashed characters ***
  94. -- Iteration 1 --
  95. string(31) "The string after addslashes is:"
  96. string(11) "Hello world"
  97. string(33) "The string after stripslashes is:"
  98. string(11) "Hello world"
  99. -- Iteration 2 --
  100. string(31) "The string after addslashes is:"
  101. string(18) "how\'re you doing?"
  102. string(33) "The string after stripslashes is:"
  103. string(17) "how're you doing?"
  104. -- Iteration 3 --
  105. string(31) "The string after addslashes is:"
  106. string(30) "don\'t disturb u\'r neighbours"
  107. string(33) "The string after stripslashes is:"
  108. string(28) "don't disturb u'r neighbours"
  109. -- Iteration 4 --
  110. string(31) "The string after addslashes is:"
  111. string(34) "don\'t disturb u\'r neighbours\'\'"
  112. string(33) "The string after stripslashes is:"
  113. string(30) "don't disturb u'r neighbours''"
  114. -- Iteration 5 --
  115. string(31) "The string after addslashes is:"
  116. string(0) ""
  117. string(33) "The string after stripslashes is:"
  118. string(0) ""
  119. -- Iteration 6 --
  120. string(31) "The string after addslashes is:"
  121. string(2) "\'"
  122. string(33) "The string after stripslashes is:"
  123. string(1) "'"
  124. -- Iteration 7 --
  125. string(31) "The string after addslashes is:"
  126. string(2) "\'"
  127. string(33) "The string after stripslashes is:"
  128. string(1) "'"
  129. -- Iteration 8 --
  130. string(31) "The string after addslashes is:"
  131. string(2) "\'"
  132. string(33) "The string after stripslashes is:"
  133. string(1) "'"
  134. -- Iteration 9 --
  135. string(31) "The string after addslashes is:"
  136. string(32) "he said, \"he will be on leave\""
  137. string(33) "The string after stripslashes is:"
  138. string(30) "he said, "he will be on leave""
  139. -- Iteration 10 --
  140. string(31) "The string after addslashes is:"
  141. string(34) "he said, \"\"he will be on leave\""
  142. string(33) "The string after stripslashes is:"
  143. string(31) "he said, ""he will be on leave""
  144. -- Iteration 11 --
  145. string(31) "The string after addslashes is:"
  146. string(15) "\"\"\"PHP\"\"\""
  147. string(33) "The string after stripslashes is:"
  148. string(9) """"PHP""""
  149. -- Iteration 12 --
  150. string(31) "The string after addslashes is:"
  151. string(0) ""
  152. string(33) "The string after stripslashes is:"
  153. string(0) ""
  154. -- Iteration 13 --
  155. string(31) "The string after addslashes is:"
  156. string(2) "\""
  157. string(33) "The string after stripslashes is:"
  158. string(1) """
  159. -- Iteration 14 --
  160. string(31) "The string after addslashes is:"
  161. string(2) "\""
  162. string(33) "The string after stripslashes is:"
  163. string(1) """
  164. -- Iteration 15 --
  165. string(31) "The string after addslashes is:"
  166. string(7) "hello\""
  167. string(33) "The string after stripslashes is:"
  168. string(6) "hello""
  169. -- Iteration 16 --
  170. string(31) "The string after addslashes is:"
  171. string(2) "\""
  172. string(33) "The string after stripslashes is:"
  173. string(1) """
  174. -- Iteration 17 --
  175. string(31) "The string after addslashes is:"
  176. string(26) "Is your name Ram\\Krishna?"
  177. string(33) "The string after stripslashes is:"
  178. string(25) "Is your name Ram\Krishna?"
  179. -- Iteration 18 --
  180. string(31) "The string after addslashes is:"
  181. string(9) "\\0.0.0.0"
  182. string(33) "The string after stripslashes is:"
  183. string(8) "\0.0.0.0"
  184. -- Iteration 19 --
  185. string(31) "The string after addslashes is:"
  186. string(31) "c:\\php\\testcase\\stripslashes"
  187. string(33) "The string after stripslashes is:"
  188. string(28) "c:\php\testcase\stripslashes"
  189. -- Iteration 20 --
  190. string(31) "The string after addslashes is:"
  191. string(2) "\\"
  192. string(33) "The string after stripslashes is:"
  193. string(1) "\"
  194. -- Iteration 21 --
  195. string(31) "The string after addslashes is:"
  196. string(2) "\\"
  197. string(33) "The string after stripslashes is:"
  198. string(1) "\"
  199. -- Iteration 22 --
  200. string(31) "The string after addslashes is:"
  201. string(12) "hello\0world"
  202. string(33) "The string after stripslashes is:"
  203. string(11) "hello�world"
  204. -- Iteration 23 --
  205. string(31) "The string after addslashes is:"
  206. string(9) "\0hello\0"
  207. string(33) "The string after stripslashes is:"
  208. string(7) "�hello�"
  209. -- Iteration 24 --
  210. string(31) "The string after addslashes is:"
  211. string(9) "\0\0hello"
  212. string(33) "The string after stripslashes is:"
  213. string(7) "��hello"
  214. -- Iteration 25 --
  215. string(31) "The string after addslashes is:"
  216. string(2) "\0"
  217. string(33) "The string after stripslashes is:"
  218. string(1) "�"
  219. -- Iteration 26 --
  220. string(31) "The string after addslashes is:"
  221. string(13) "\'\\0.0.0.0\'"
  222. string(33) "The string after stripslashes is:"
  223. string(10) "'\0.0.0.0'"
  224. -- Iteration 27 --
  225. string(31) "The string after addslashes is:"
  226. string(15) "\'\\0.0.0.0\'\0"
  227. string(33) "The string after stripslashes is:"
  228. string(11) "'\0.0.0.0'�"
  229. -- Iteration 28 --
  230. string(31) "The string after addslashes is:"
  231. string(15) "\0\'c:\\php\\\'"
  232. string(33) "The string after stripslashes is:"
  233. string(10) "�'c:\php\'"
  234. -- Iteration 29 --
  235. string(31) "The string after addslashes is:"
  236. string(13) "\"\\0.0.0.0\""
  237. string(33) "The string after stripslashes is:"
  238. string(10) ""\0.0.0.0""
  239. -- Iteration 30 --
  240. string(31) "The string after addslashes is:"
  241. string(17) "\"c:\\php\\\"\0\'"
  242. string(33) "The string after stripslashes is:"
  243. string(11) ""c:\php\"�'"
  244. -- Iteration 31 --
  245. string(31) "The string after addslashes is:"
  246. string(22) "\"hello\"\'world\'\0//"
  247. string(33) "The string after stripslashes is:"
  248. string(17) ""hello"'world'�//"
  249. -- Iteration 32 --
  250. string(31) "The string after addslashes is:"
  251. string(18) "0xABCDEF0123456789"
  252. string(33) "The string after stripslashes is:"
  253. string(18) "0xABCDEF0123456789"
  254. -- Iteration 33 --
  255. string(31) "The string after addslashes is:"
  256. string(2) "\0"
  257. string(33) "The string after stripslashes is:"
  258. string(1) "�"
  259. -- Iteration 34 --
  260. string(31) "The string after addslashes is:"
  261. string(18) "!@#$%&*@$%#&/;:,<>"
  262. string(33) "The string after stripslashes is:"
  263. string(18) "!@#$%&*@$%#&/;:,<>"
  264. -- Iteration 35 --
  265. string(31) "The string after addslashes is:"
  266. string(12) "hello\0world"
  267. string(33) "The string after stripslashes is:"
  268. string(11) "hello�world"
  269. -- Iteration 36 --
  270. string(31) "The string after addslashes is:"
  271. string(73) "This is line 1 of \'heredoc\' string
  272. This is line 2 of \"heredoc\" string"
  273. string(33) "The string after stripslashes is:"
  274. string(69) "This is line 1 of 'heredoc' string
  275. This is line 2 of "heredoc" string"
  276. -- Iteration 37 --
  277. string(31) "The string after addslashes is:"
  278. string(0) ""
  279. string(33) "The string after stripslashes is:"
  280. string(0) ""
  281. Done