PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ext/standard/tests/strings/addslashes_variation3.phpt

http://github.com/infusion/PHP
Unknown | 196 lines | 147 code | 49 blank | 0 comment | 0 complexity | 1fcc7da2fbff835e75e35d348b761bb7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. --TEST--
  2. Test addslashes() function : usage variations - with magic_quotes_sybase directive ON
  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. * Test addslashes() with PHP directive magic_quotes_sybase set ON
  11. */
  12. echo "*** Testing addslashes() : 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. '\\0.0.0.0',
  44. 'c:\php\testcase\addslashes',
  45. '\\',
  46. // string with nul characters
  47. 'hello'.chr(0).'world',
  48. chr(0).'hello'.chr(0),
  49. chr(0).chr(0).'hello',
  50. chr(0),
  51. // mixed strings
  52. "'\\0.0.0.0'",
  53. "'\\0.0.0.0'".chr(0),
  54. chr(0)."'c:\php\'",
  55. '"\\0.0.0.0"',
  56. '"c:\php\"'.chr(0)."'",
  57. '"hello"'."'world'".chr(0).'//',
  58. // string with hexadecimal number
  59. "0xABCDEF0123456789",
  60. "\xabcdef0123456789",
  61. '!@#$%&*@$%#&/;:,<>',
  62. "hello\x00world",
  63. // heredoc strings
  64. $heredoc_string,
  65. $heredoc_null_string
  66. );
  67. $count = 1;
  68. // looping to test for all strings in $str_array
  69. foreach( $str_array as $str ) {
  70. echo "\n-- Iteration $count --\n";
  71. var_dump( addslashes($str) );
  72. $count ++;
  73. }
  74. echo "Done\n";
  75. ?>
  76. --EXPECTF--
  77. *** Testing addslashes() : with php directive magic_quotes_sybase set ON ***
  78. -- Iteration 1 --
  79. string(11) "Hello world"
  80. -- Iteration 2 --
  81. string(18) "how''re you doing?"
  82. -- Iteration 3 --
  83. string(30) "don''t disturb u''r neighbours"
  84. -- Iteration 4 --
  85. string(34) "don''t disturb u''r neighbours''''"
  86. -- Iteration 5 --
  87. string(0) ""
  88. -- Iteration 6 --
  89. string(2) "''"
  90. -- Iteration 7 --
  91. string(2) "''"
  92. -- Iteration 8 --
  93. string(30) "he said, "he will be on leave""
  94. -- Iteration 9 --
  95. string(31) "he said, ""he will be on leave""
  96. -- Iteration 10 --
  97. string(9) """"PHP""""
  98. -- Iteration 11 --
  99. string(0) ""
  100. -- Iteration 12 --
  101. string(1) """
  102. -- Iteration 13 --
  103. string(1) """
  104. -- Iteration 14 --
  105. string(6) "hello""
  106. -- Iteration 15 --
  107. string(25) "Is your name Ram\Krishna?"
  108. -- Iteration 16 --
  109. string(8) "\0.0.0.0"
  110. -- Iteration 17 --
  111. string(26) "c:\php\testcase\addslashes"
  112. -- Iteration 18 --
  113. string(1) "\"
  114. -- Iteration 19 --
  115. string(12) "hello\0world"
  116. -- Iteration 20 --
  117. string(9) "\0hello\0"
  118. -- Iteration 21 --
  119. string(9) "\0\0hello"
  120. -- Iteration 22 --
  121. string(2) "\0"
  122. -- Iteration 23 --
  123. string(12) "''\0.0.0.0''"
  124. -- Iteration 24 --
  125. string(14) "''\0.0.0.0''\0"
  126. -- Iteration 25 --
  127. string(13) "\0''c:\php\''"
  128. -- Iteration 26 --
  129. string(10) ""\0.0.0.0""
  130. -- Iteration 27 --
  131. string(13) ""c:\php\"\0''"
  132. -- Iteration 28 --
  133. string(20) ""hello"''world''\0//"
  134. -- Iteration 29 --
  135. string(18) "0xABCDEF0123456789"
  136. -- Iteration 30 --
  137. string(15) "Ťcdef0123456789"
  138. -- Iteration 31 --
  139. string(18) "!@#$%&*@$%#&/;:,<>"
  140. -- Iteration 32 --
  141. string(12) "hello\0world"
  142. -- Iteration 33 --
  143. string(71) "This is line 1 of ''heredoc'' string
  144. This is line 2 of "heredoc" string"
  145. -- Iteration 34 --
  146. string(0) ""
  147. Done