MediaWiki REL1_31
wfParseUrlTest.php
Go to the documentation of this file.
1<?php
28 protected function setUp() {
29 parent::setUp();
30
31 $this->setMwGlobals( 'wgUrlProtocols', [
32 '//',
33 'http://',
34 'https://',
35 'file://',
36 'mailto:',
37 ] );
38 }
39
43 public function testWfParseUrl( $url, $parts ) {
44 $this->assertEquals(
45 $parts,
46 wfParseUrl( $url )
47 );
48 }
49
55 public static function provideURLs() {
56 return [
57 [
58 '//example.org',
59 [
60 'scheme' => '',
61 'delimiter' => '//',
62 'host' => 'example.org',
63 ]
64 ],
65 [
66 'http://example.org',
67 [
68 'scheme' => 'http',
69 'delimiter' => '://',
70 'host' => 'example.org',
71 ]
72 ],
73 [
74 'https://example.org',
75 [
76 'scheme' => 'https',
77 'delimiter' => '://',
78 'host' => 'example.org',
79 ]
80 ],
81 [
82 'http://id:key@example.org:123/path?foo=bar#baz',
83 [
84 'scheme' => 'http',
85 'delimiter' => '://',
86 'user' => 'id',
87 'pass' => 'key',
88 'host' => 'example.org',
89 'port' => 123,
90 'path' => '/path',
91 'query' => 'foo=bar',
92 'fragment' => 'baz',
93 ]
94 ],
95 [
96 'file://example.org/etc/php.ini',
97 [
98 'scheme' => 'file',
99 'delimiter' => '://',
100 'host' => 'example.org',
101 'path' => '/etc/php.ini',
102 ]
103 ],
104 [
105 'file:///etc/php.ini',
106 [
107 'scheme' => 'file',
108 'delimiter' => '://',
109 'host' => '',
110 'path' => '/etc/php.ini',
111 ]
112 ],
113 [
114 'file:///c:/',
115 [
116 'scheme' => 'file',
117 'delimiter' => '://',
118 'host' => '',
119 'path' => '/c:/',
120 ]
121 ],
122 [
123 'mailto:id@example.org',
124 [
125 'scheme' => 'mailto',
126 'delimiter' => ':',
127 'host' => 'id@example.org',
128 'path' => '',
129 ]
130 ],
131 [
132 'mailto:id@example.org?subject=Foo',
133 [
134 'scheme' => 'mailto',
135 'delimiter' => ':',
136 'host' => 'id@example.org',
137 'path' => '',
138 'query' => 'subject=Foo',
139 ]
140 ],
141 [
142 'mailto:?subject=Foo',
143 [
144 'scheme' => 'mailto',
145 'delimiter' => ':',
146 'host' => '',
147 'path' => '',
148 'query' => 'subject=Foo',
149 ]
150 ],
151 [
152 'invalid://test/',
153 false
154 ],
155 // T212067
156 [
157 '//evil.com?example.org/foo/bar',
158 [
159 'scheme' => '',
160 'delimiter' => '//',
161 'host' => 'evil.com',
162 'query' => 'example.org/foo/bar',
163 ]
164 ],
165 [
166 '//evil.com?example.org/foo/bar?baz#quux',
167 [
168 'scheme' => '',
169 'delimiter' => '//',
170 'host' => 'evil.com',
171 'query' => 'example.org/foo/bar?baz',
172 'fragment' => 'quux',
173 ]
174 ],
175 [
176 '//evil.com?example.org?baz#quux',
177 [
178 'scheme' => '',
179 'delimiter' => '//',
180 'host' => 'evil.com',
181 'query' => 'example.org?baz',
182 'fragment' => 'quux',
183 ]
184 ],
185 [
186 '//evil.com?example.org#quux',
187 [
188 'scheme' => '',
189 'delimiter' => '//',
190 'host' => 'evil.com',
191 'query' => 'example.org',
192 'fragment' => 'quux',
193 ]
194 ],
195 ];
196 }
197}
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
GlobalFunctions wfParseUrl.
static provideURLs()
Provider of URLs for testing wfParseUrl()
testWfParseUrl( $url, $parts)
provideURLs
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187