PageRenderTime 40ms CodeModel.GetById 32ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

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