xref: /PHP-8.4/ext/filter/tests/015.phpt (revision 74859783)
1--TEST--
2filter_var() and FILTER_VALIDATE_URL
3--EXTENSIONS--
4filter
5--FILE--
6<?php
7
8$values = Array(
9'http://example.com/index.html',
10'http://www.example.com/index.php',
11'http://www.example/img/test.png',
12'http://www.example/img/dir/',
13'http://www.example/img/dir',
14'http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/',
15'http://toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.com',
16'http://eauBcFReEmjLcoZwI0RuONNnwU4H9r151juCaqTI5VeIP5jcYIqhx1lh5vV00l2rTs6y7hOp7rYw42QZiq6VIzjcYrRm8gFRMk9U9Wi1grL8Mr5kLVloYLthHgyA94QK3SaXCATklxgo6XvcbXIqAGG7U0KxTr8hJJU1p2ZQ2mXHmp4DhYP8N9SRuEKzaCPcSIcW7uj21jZqBigsLsNAXEzU8SPXZjmVQVtwQATPWeWyGW4GuJhjP4Q8o0.com',
17'http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com.',
18'http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58R.example.com',
19'http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]',
20'http://[2001:db8:0:85a3:0:0:ac1f:8001]:123/me.html',
21'http://[2001:db8:0:85a3::ac1f:8001]/',
22'http://[::1]',
23'http://cont-ains.h-yph-en-s.com',
24'http://..com',
25'http://a.-bc.com',
26'http://ab.cd-.com',
27'http://-.abc.com',
28'http://abc.-.abc.com',
29'http://underscore_.example.com',
30'http//www.example/wrong/url/',
31'http:/www.example',
32'file:///tmp/test.c',
33'ftp://ftp.example.com/tmp/',
34'/tmp/test.c',
35'/',
36'http://',
37'http:/',
38'http:',
39'http',
40'',
41-1,
42array(),
43'mailto:foo@bar.com',
44'news:news.php.net',
45'file://foo/bar',
46"http://\r\n/bar",
47"http://example.com:qq",
48"http://example.com:-2",
49"http://example.com:65536",
50"http://example.com:65537",
51);
52foreach ($values as $value) {
53    var_dump(filter_var($value, FILTER_VALIDATE_URL));
54}
55
56
57var_dump(filter_var("qwe", FILTER_VALIDATE_URL));
58var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL));
59var_dump(filter_var("http://", FILTER_VALIDATE_URL));
60var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL));
61var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL));
62var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));
63var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED));
64var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED));
65var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED));
66
67echo "Done\n";
68?>
69--EXPECT--
70string(29) "http://example.com/index.html"
71string(32) "http://www.example.com/index.php"
72string(31) "http://www.example/img/test.png"
73string(27) "http://www.example/img/dir/"
74string(26) "http://www.example/img/dir"
75string(79) "http://www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/"
76bool(false)
77bool(false)
78string(261) "http://kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com."
79bool(false)
80string(48) "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]"
81string(50) "http://[2001:db8:0:85a3:0:0:ac1f:8001]:123/me.html"
82string(36) "http://[2001:db8:0:85a3::ac1f:8001]/"
83string(12) "http://[::1]"
84string(31) "http://cont-ains.h-yph-en-s.com"
85bool(false)
86bool(false)
87bool(false)
88bool(false)
89bool(false)
90bool(false)
91bool(false)
92bool(false)
93string(18) "file:///tmp/test.c"
94string(26) "ftp://ftp.example.com/tmp/"
95bool(false)
96bool(false)
97bool(false)
98bool(false)
99bool(false)
100bool(false)
101bool(false)
102bool(false)
103bool(false)
104string(18) "mailto:foo@bar.com"
105string(17) "news:news.php.net"
106string(14) "file://foo/bar"
107bool(false)
108bool(false)
109bool(false)
110bool(false)
111bool(false)
112bool(false)
113string(10) "http://qwe"
114bool(false)
115bool(false)
116string(22) "http://www.example.com"
117bool(false)
118string(42) "http://www.example.com/path/at/the/server/"
119bool(false)
120string(40) "http://www.example.com/index.php?a=b&c=d"
121Done
122