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