1--TEST--
2Test parse_url() function: Parse a load of URLs without specifying the component
3--FILE--
4<?php
5/*
6 * Parse a load of URLs without specifying the component
7 */
8include_once(__DIR__ . '/urls.inc');
9
10foreach ($urls as $url) {
11    echo "\n--> $url: ";
12    var_dump(parse_url($url));
13}
14
15echo "Done";
16?>
17--EXPECT--
18--> 64.246.30.37: array(1) {
19  ["path"]=>
20  string(12) "64.246.30.37"
21}
22
23--> http://64.246.30.37: array(2) {
24  ["scheme"]=>
25  string(4) "http"
26  ["host"]=>
27  string(12) "64.246.30.37"
28}
29
30--> http://64.246.30.37/: array(3) {
31  ["scheme"]=>
32  string(4) "http"
33  ["host"]=>
34  string(12) "64.246.30.37"
35  ["path"]=>
36  string(1) "/"
37}
38
39--> 64.246.30.37/: array(1) {
40  ["path"]=>
41  string(13) "64.246.30.37/"
42}
43
44--> 64.246.30.37:80/: array(3) {
45  ["host"]=>
46  string(12) "64.246.30.37"
47  ["port"]=>
48  int(80)
49  ["path"]=>
50  string(1) "/"
51}
52
53--> php.net: array(1) {
54  ["path"]=>
55  string(7) "php.net"
56}
57
58--> php.net/: array(1) {
59  ["path"]=>
60  string(8) "php.net/"
61}
62
63--> http://php.net: array(2) {
64  ["scheme"]=>
65  string(4) "http"
66  ["host"]=>
67  string(7) "php.net"
68}
69
70--> http://php.net/: array(3) {
71  ["scheme"]=>
72  string(4) "http"
73  ["host"]=>
74  string(7) "php.net"
75  ["path"]=>
76  string(1) "/"
77}
78
79--> www.php.net: array(1) {
80  ["path"]=>
81  string(11) "www.php.net"
82}
83
84--> www.php.net/: array(1) {
85  ["path"]=>
86  string(12) "www.php.net/"
87}
88
89--> http://www.php.net: array(2) {
90  ["scheme"]=>
91  string(4) "http"
92  ["host"]=>
93  string(11) "www.php.net"
94}
95
96--> http://www.php.net/: array(3) {
97  ["scheme"]=>
98  string(4) "http"
99  ["host"]=>
100  string(11) "www.php.net"
101  ["path"]=>
102  string(1) "/"
103}
104
105--> www.php.net:80: array(2) {
106  ["host"]=>
107  string(11) "www.php.net"
108  ["port"]=>
109  int(80)
110}
111
112--> http://www.php.net:80: array(3) {
113  ["scheme"]=>
114  string(4) "http"
115  ["host"]=>
116  string(11) "www.php.net"
117  ["port"]=>
118  int(80)
119}
120
121--> http://www.php.net:80/: array(4) {
122  ["scheme"]=>
123  string(4) "http"
124  ["host"]=>
125  string(11) "www.php.net"
126  ["port"]=>
127  int(80)
128  ["path"]=>
129  string(1) "/"
130}
131
132--> http://www.php.net/index.php: array(3) {
133  ["scheme"]=>
134  string(4) "http"
135  ["host"]=>
136  string(11) "www.php.net"
137  ["path"]=>
138  string(10) "/index.php"
139}
140
141--> www.php.net/?: array(2) {
142  ["path"]=>
143  string(12) "www.php.net/"
144  ["query"]=>
145  string(0) ""
146}
147
148--> www.php.net:80/?: array(4) {
149  ["host"]=>
150  string(11) "www.php.net"
151  ["port"]=>
152  int(80)
153  ["path"]=>
154  string(1) "/"
155  ["query"]=>
156  string(0) ""
157}
158
159--> http://www.php.net/?: array(4) {
160  ["scheme"]=>
161  string(4) "http"
162  ["host"]=>
163  string(11) "www.php.net"
164  ["path"]=>
165  string(1) "/"
166  ["query"]=>
167  string(0) ""
168}
169
170--> http://www.php.net:80/?: array(5) {
171  ["scheme"]=>
172  string(4) "http"
173  ["host"]=>
174  string(11) "www.php.net"
175  ["port"]=>
176  int(80)
177  ["path"]=>
178  string(1) "/"
179  ["query"]=>
180  string(0) ""
181}
182
183--> http://www.php.net:80/index.php: array(4) {
184  ["scheme"]=>
185  string(4) "http"
186  ["host"]=>
187  string(11) "www.php.net"
188  ["port"]=>
189  int(80)
190  ["path"]=>
191  string(10) "/index.php"
192}
193
194--> http://www.php.net:80/foo/bar/index.php: array(4) {
195  ["scheme"]=>
196  string(4) "http"
197  ["host"]=>
198  string(11) "www.php.net"
199  ["port"]=>
200  int(80)
201  ["path"]=>
202  string(18) "/foo/bar/index.php"
203}
204
205--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) {
206  ["scheme"]=>
207  string(4) "http"
208  ["host"]=>
209  string(11) "www.php.net"
210  ["port"]=>
211  int(80)
212  ["path"]=>
213  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
214}
215
216--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2&parameters=3&too=4&here=5: array(5) {
217  ["scheme"]=>
218  string(4) "http"
219  ["host"]=>
220  string(11) "www.php.net"
221  ["port"]=>
222  int(80)
223  ["path"]=>
224  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
225  ["query"]=>
226  string(37) "lots=1&of=2&parameters=3&too=4&here=5"
227}
228
229--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/: array(4) {
230  ["scheme"]=>
231  string(4) "http"
232  ["host"]=>
233  string(11) "www.php.net"
234  ["port"]=>
235  int(80)
236  ["path"]=>
237  string(45) "/this/is/a/very/deep/directory/structure/and/"
238}
239
240--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php: array(4) {
241  ["scheme"]=>
242  string(4) "http"
243  ["host"]=>
244  string(11) "www.php.net"
245  ["port"]=>
246  int(80)
247  ["path"]=>
248  string(53) "/this/is/a/very/deep/directory/structure/and/file.php"
249}
250
251--> http://www.php.net:80/this/../a/../deep/directory: array(4) {
252  ["scheme"]=>
253  string(4) "http"
254  ["host"]=>
255  string(11) "www.php.net"
256  ["port"]=>
257  int(80)
258  ["path"]=>
259  string(28) "/this/../a/../deep/directory"
260}
261
262--> http://www.php.net:80/this/../a/../deep/directory/: array(4) {
263  ["scheme"]=>
264  string(4) "http"
265  ["host"]=>
266  string(11) "www.php.net"
267  ["port"]=>
268  int(80)
269  ["path"]=>
270  string(29) "/this/../a/../deep/directory/"
271}
272
273--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php: array(4) {
274  ["scheme"]=>
275  string(4) "http"
276  ["host"]=>
277  string(11) "www.php.net"
278  ["port"]=>
279  int(80)
280  ["path"]=>
281  string(42) "/this/is/a/very/deep/directory/../file.php"
282}
283
284--> http://www.php.net:80/index.php: array(4) {
285  ["scheme"]=>
286  string(4) "http"
287  ["host"]=>
288  string(11) "www.php.net"
289  ["port"]=>
290  int(80)
291  ["path"]=>
292  string(10) "/index.php"
293}
294
295--> http://www.php.net:80/index.php?: array(5) {
296  ["scheme"]=>
297  string(4) "http"
298  ["host"]=>
299  string(11) "www.php.net"
300  ["port"]=>
301  int(80)
302  ["path"]=>
303  string(10) "/index.php"
304  ["query"]=>
305  string(0) ""
306}
307
308--> http://www.php.net:80/#foo: array(5) {
309  ["scheme"]=>
310  string(4) "http"
311  ["host"]=>
312  string(11) "www.php.net"
313  ["port"]=>
314  int(80)
315  ["path"]=>
316  string(1) "/"
317  ["fragment"]=>
318  string(3) "foo"
319}
320
321--> http://www.php.net:80/?#: array(6) {
322  ["scheme"]=>
323  string(4) "http"
324  ["host"]=>
325  string(11) "www.php.net"
326  ["port"]=>
327  int(80)
328  ["path"]=>
329  string(1) "/"
330  ["query"]=>
331  string(0) ""
332  ["fragment"]=>
333  string(0) ""
334}
335
336--> http://www.php.net:80/?test=1: array(5) {
337  ["scheme"]=>
338  string(4) "http"
339  ["host"]=>
340  string(11) "www.php.net"
341  ["port"]=>
342  int(80)
343  ["path"]=>
344  string(1) "/"
345  ["query"]=>
346  string(6) "test=1"
347}
348
349--> http://www.php.net/?test=1&: array(4) {
350  ["scheme"]=>
351  string(4) "http"
352  ["host"]=>
353  string(11) "www.php.net"
354  ["path"]=>
355  string(1) "/"
356  ["query"]=>
357  string(7) "test=1&"
358}
359
360--> http://www.php.net:80/?&: array(5) {
361  ["scheme"]=>
362  string(4) "http"
363  ["host"]=>
364  string(11) "www.php.net"
365  ["port"]=>
366  int(80)
367  ["path"]=>
368  string(1) "/"
369  ["query"]=>
370  string(1) "&"
371}
372
373--> http://www.php.net:80/index.php?test=1&: array(5) {
374  ["scheme"]=>
375  string(4) "http"
376  ["host"]=>
377  string(11) "www.php.net"
378  ["port"]=>
379  int(80)
380  ["path"]=>
381  string(10) "/index.php"
382  ["query"]=>
383  string(7) "test=1&"
384}
385
386--> http://www.php.net/index.php?&: array(4) {
387  ["scheme"]=>
388  string(4) "http"
389  ["host"]=>
390  string(11) "www.php.net"
391  ["path"]=>
392  string(10) "/index.php"
393  ["query"]=>
394  string(1) "&"
395}
396
397--> http://www.php.net:80/index.php?foo&: array(5) {
398  ["scheme"]=>
399  string(4) "http"
400  ["host"]=>
401  string(11) "www.php.net"
402  ["port"]=>
403  int(80)
404  ["path"]=>
405  string(10) "/index.php"
406  ["query"]=>
407  string(4) "foo&"
408}
409
410--> http://www.php.net/index.php?&foo: array(4) {
411  ["scheme"]=>
412  string(4) "http"
413  ["host"]=>
414  string(11) "www.php.net"
415  ["path"]=>
416  string(10) "/index.php"
417  ["query"]=>
418  string(4) "&foo"
419}
420
421--> http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI: array(5) {
422  ["scheme"]=>
423  string(4) "http"
424  ["host"]=>
425  string(11) "www.php.net"
426  ["port"]=>
427  int(80)
428  ["path"]=>
429  string(10) "/index.php"
430  ["query"]=>
431  string(31) "test=1&test2=char&test3=mixesCI"
432}
433
434--> www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(5) {
435  ["host"]=>
436  string(11) "www.php.net"
437  ["port"]=>
438  int(80)
439  ["path"]=>
440  string(10) "/index.php"
441  ["query"]=>
442  string(31) "test=1&test2=char&test3=mixesCI"
443  ["fragment"]=>
444  string(16) "some_page_ref123"
445}
446
447--> http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
448  ["scheme"]=>
449  string(4) "http"
450  ["host"]=>
451  string(11) "www.php.net"
452  ["port"]=>
453  int(80)
454  ["user"]=>
455  string(6) "secret"
456  ["path"]=>
457  string(10) "/index.php"
458  ["query"]=>
459  string(31) "test=1&test2=char&test3=mixesCI"
460  ["fragment"]=>
461  string(16) "some_page_ref123"
462}
463
464--> http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
465  ["scheme"]=>
466  string(4) "http"
467  ["host"]=>
468  string(11) "www.php.net"
469  ["user"]=>
470  string(6) "secret"
471  ["pass"]=>
472  string(0) ""
473  ["path"]=>
474  string(10) "/index.php"
475  ["query"]=>
476  string(31) "test=1&test2=char&test3=mixesCI"
477  ["fragment"]=>
478  string(16) "some_page_ref123"
479}
480
481--> http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
482  ["scheme"]=>
483  string(4) "http"
484  ["host"]=>
485  string(11) "www.php.net"
486  ["port"]=>
487  int(80)
488  ["user"]=>
489  string(0) ""
490  ["pass"]=>
491  string(7) "hideout"
492  ["path"]=>
493  string(10) "/index.php"
494  ["query"]=>
495  string(31) "test=1&test2=char&test3=mixesCI"
496  ["fragment"]=>
497  string(16) "some_page_ref123"
498}
499
500--> http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
501  ["scheme"]=>
502  string(4) "http"
503  ["host"]=>
504  string(11) "www.php.net"
505  ["user"]=>
506  string(6) "secret"
507  ["pass"]=>
508  string(7) "hideout"
509  ["path"]=>
510  string(10) "/index.php"
511  ["query"]=>
512  string(31) "test=1&test2=char&test3=mixesCI"
513  ["fragment"]=>
514  string(16) "some_page_ref123"
515}
516
517--> http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(7) {
518  ["scheme"]=>
519  string(4) "http"
520  ["host"]=>
521  string(11) "www.php.net"
522  ["port"]=>
523  int(80)
524  ["user"]=>
525  string(14) "secret@hideout"
526  ["path"]=>
527  string(10) "/index.php"
528  ["query"]=>
529  string(31) "test=1&test2=char&test3=mixesCI"
530  ["fragment"]=>
531  string(16) "some_page_ref123"
532}
533
534--> http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123: array(8) {
535  ["scheme"]=>
536  string(4) "http"
537  ["host"]=>
538  string(11) "www.php.net"
539  ["port"]=>
540  int(80)
541  ["user"]=>
542  string(6) "secret"
543  ["pass"]=>
544  string(7) "hid:out"
545  ["path"]=>
546  string(10) "/index.php"
547  ["query"]=>
548  string(31) "test=1&test2=char&test3=mixesCI"
549  ["fragment"]=>
550  string(16) "some_page_ref123"
551}
552
553--> nntp://news.php.net: array(2) {
554  ["scheme"]=>
555  string(4) "nntp"
556  ["host"]=>
557  string(12) "news.php.net"
558}
559
560--> ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz: array(3) {
561  ["scheme"]=>
562  string(3) "ftp"
563  ["host"]=>
564  string(11) "ftp.gnu.org"
565  ["path"]=>
566  string(22) "/gnu/glic/glibc.tar.gz"
567}
568
569--> zlib:http://foo@bar: array(2) {
570  ["scheme"]=>
571  string(4) "zlib"
572  ["path"]=>
573  string(14) "http://foo@bar"
574}
575
576--> zlib:filename.txt: array(2) {
577  ["scheme"]=>
578  string(4) "zlib"
579  ["path"]=>
580  string(12) "filename.txt"
581}
582
583--> zlib:/path/to/my/file/file.txt: array(2) {
584  ["scheme"]=>
585  string(4) "zlib"
586  ["path"]=>
587  string(25) "/path/to/my/file/file.txt"
588}
589
590--> foo://foo@bar: array(3) {
591  ["scheme"]=>
592  string(3) "foo"
593  ["host"]=>
594  string(3) "bar"
595  ["user"]=>
596  string(3) "foo"
597}
598
599--> mailto:me@mydomain.com: array(2) {
600  ["scheme"]=>
601  string(6) "mailto"
602  ["path"]=>
603  string(15) "me@mydomain.com"
604}
605
606--> /foo.php?a=b&c=d: array(2) {
607  ["path"]=>
608  string(8) "/foo.php"
609  ["query"]=>
610  string(7) "a=b&c=d"
611}
612
613--> foo.php?a=b&c=d: array(2) {
614  ["path"]=>
615  string(7) "foo.php"
616  ["query"]=>
617  string(7) "a=b&c=d"
618}
619
620--> http://user:passwd@www.example.com:8080?bar=1&boom=0: array(6) {
621  ["scheme"]=>
622  string(4) "http"
623  ["host"]=>
624  string(15) "www.example.com"
625  ["port"]=>
626  int(8080)
627  ["user"]=>
628  string(4) "user"
629  ["pass"]=>
630  string(6) "passwd"
631  ["query"]=>
632  string(12) "bar=1&boom=0"
633}
634
635--> http://user_me-you:my_pas-word@www.example.com:8080?bar=1&boom=0: array(6) {
636  ["scheme"]=>
637  string(4) "http"
638  ["host"]=>
639  string(15) "www.example.com"
640  ["port"]=>
641  int(8080)
642  ["user"]=>
643  string(11) "user_me-you"
644  ["pass"]=>
645  string(11) "my_pas-word"
646  ["query"]=>
647  string(12) "bar=1&boom=0"
648}
649
650--> file:///path/to/file: array(2) {
651  ["scheme"]=>
652  string(4) "file"
653  ["path"]=>
654  string(13) "/path/to/file"
655}
656
657--> file://path/to/file: array(3) {
658  ["scheme"]=>
659  string(4) "file"
660  ["host"]=>
661  string(4) "path"
662  ["path"]=>
663  string(8) "/to/file"
664}
665
666--> file:/path/to/file: array(2) {
667  ["scheme"]=>
668  string(4) "file"
669  ["path"]=>
670  string(13) "/path/to/file"
671}
672
673--> http://1.2.3.4:/abc.asp?a=1&b=2: array(4) {
674  ["scheme"]=>
675  string(4) "http"
676  ["host"]=>
677  string(7) "1.2.3.4"
678  ["path"]=>
679  string(8) "/abc.asp"
680  ["query"]=>
681  string(7) "a=1&b=2"
682}
683
684--> http://foo.com#bar: array(3) {
685  ["scheme"]=>
686  string(4) "http"
687  ["host"]=>
688  string(7) "foo.com"
689  ["fragment"]=>
690  string(3) "bar"
691}
692
693--> scheme:: array(1) {
694  ["scheme"]=>
695  string(6) "scheme"
696}
697
698--> foo+bar://baz@bang/bla: array(4) {
699  ["scheme"]=>
700  string(7) "foo+bar"
701  ["host"]=>
702  string(4) "bang"
703  ["user"]=>
704  string(3) "baz"
705  ["path"]=>
706  string(4) "/bla"
707}
708
709--> gg:9130731: array(2) {
710  ["scheme"]=>
711  string(2) "gg"
712  ["path"]=>
713  string(7) "9130731"
714}
715
716--> http://user:@pass@host/path?argument?value#etc: array(7) {
717  ["scheme"]=>
718  string(4) "http"
719  ["host"]=>
720  string(4) "host"
721  ["user"]=>
722  string(4) "user"
723  ["pass"]=>
724  string(5) "@pass"
725  ["path"]=>
726  string(5) "/path"
727  ["query"]=>
728  string(14) "argument?value"
729  ["fragment"]=>
730  string(3) "etc"
731}
732
733--> http://10.10.10.10/:80: array(3) {
734  ["scheme"]=>
735  string(4) "http"
736  ["host"]=>
737  string(11) "10.10.10.10"
738  ["path"]=>
739  string(4) "/:80"
740}
741
742--> http://x:?: array(3) {
743  ["scheme"]=>
744  string(4) "http"
745  ["host"]=>
746  string(1) "x"
747  ["query"]=>
748  string(0) ""
749}
750
751--> x:blah.com: array(2) {
752  ["scheme"]=>
753  string(1) "x"
754  ["path"]=>
755  string(8) "blah.com"
756}
757
758--> x:/blah.com: array(2) {
759  ["scheme"]=>
760  string(1) "x"
761  ["path"]=>
762  string(9) "/blah.com"
763}
764
765--> x://::abc/?: bool(false)
766
767--> http://::?: array(3) {
768  ["scheme"]=>
769  string(4) "http"
770  ["host"]=>
771  string(1) ":"
772  ["query"]=>
773  string(0) ""
774}
775
776--> http://::#: array(3) {
777  ["scheme"]=>
778  string(4) "http"
779  ["host"]=>
780  string(1) ":"
781  ["fragment"]=>
782  string(0) ""
783}
784
785--> x://::6.5: array(3) {
786  ["scheme"]=>
787  string(1) "x"
788  ["host"]=>
789  string(1) ":"
790  ["port"]=>
791  int(6)
792}
793
794--> http://?:/: bool(false)
795
796--> http://@?:/: bool(false)
797
798--> file:///:: array(2) {
799  ["scheme"]=>
800  string(4) "file"
801  ["path"]=>
802  string(2) "/:"
803}
804
805--> file:///a:/: array(2) {
806  ["scheme"]=>
807  string(4) "file"
808  ["path"]=>
809  string(3) "a:/"
810}
811
812--> file:///ab:/: array(2) {
813  ["scheme"]=>
814  string(4) "file"
815  ["path"]=>
816  string(5) "/ab:/"
817}
818
819--> file:///a:/: array(2) {
820  ["scheme"]=>
821  string(4) "file"
822  ["path"]=>
823  string(3) "a:/"
824}
825
826--> file:///@:/: array(2) {
827  ["scheme"]=>
828  string(4) "file"
829  ["path"]=>
830  string(3) "@:/"
831}
832
833--> file:///:80/: array(2) {
834  ["scheme"]=>
835  string(4) "file"
836  ["path"]=>
837  string(5) "/:80/"
838}
839
840--> []: array(1) {
841  ["path"]=>
842  string(2) "[]"
843}
844
845--> http://[x:80]/: array(3) {
846  ["scheme"]=>
847  string(4) "http"
848  ["host"]=>
849  string(6) "[x:80]"
850  ["path"]=>
851  string(1) "/"
852}
853
854--> : array(1) {
855  ["path"]=>
856  string(0) ""
857}
858
859--> /: array(1) {
860  ["path"]=>
861  string(1) "/"
862}
863
864--> /rest/Users?filter={"id":"123"}: array(2) {
865  ["path"]=>
866  string(11) "/rest/Users"
867  ["query"]=>
868  string(19) "filter={"id":"123"}"
869}
870
871--> %:x: array(1) {
872  ["path"]=>
873  string(3) "%:x"
874}
875
876--> https://example.com:0/: array(4) {
877  ["scheme"]=>
878  string(5) "https"
879  ["host"]=>
880  string(11) "example.com"
881  ["port"]=>
882  int(0)
883  ["path"]=>
884  string(1) "/"
885}
886
887--> http:///blah.com: bool(false)
888
889--> http://:80: bool(false)
890
891--> http://user@:80: bool(false)
892
893--> http://user:pass@:80: bool(false)
894
895--> http://:: bool(false)
896
897--> http://@/: bool(false)
898
899--> http://@:/: bool(false)
900
901--> http://:/: bool(false)
902
903--> http://?: bool(false)
904
905--> http://#: bool(false)
906
907--> http://?:: bool(false)
908
909--> http://:?: bool(false)
910
911--> http://blah.com:123456: bool(false)
912
913--> http://blah.com:abcdef: bool(false)
914Done
915