setMwGlobals( 'wgUrlProtocols', [ '//', 'http://', 'https://', 'file://', 'mailto:', ] ); } /** * @dataProvider provideURLs */ public function testWfParseUrl( $url, $parts ) { $this->assertEquals( $parts, wfParseUrl( $url ) ); } /** * Provider of URLs for testing wfParseUrl() * * @return array */ public static function provideURLs() { return [ [ '//example.org', [ 'scheme' => '', 'delimiter' => '//', 'host' => 'example.org', ] ], [ 'http://example.org', [ 'scheme' => 'http', 'delimiter' => '://', 'host' => 'example.org', ] ], [ 'https://example.org', [ 'scheme' => 'https', 'delimiter' => '://', 'host' => 'example.org', ] ], [ 'http://id:key@example.org:123/path?foo=bar#baz', [ 'scheme' => 'http', 'delimiter' => '://', 'user' => 'id', 'pass' => 'key', 'host' => 'example.org', 'port' => 123, 'path' => '/path', 'query' => 'foo=bar', 'fragment' => 'baz', ] ], [ 'file://example.org/etc/php.ini', [ 'scheme' => 'file', 'delimiter' => '://', 'host' => 'example.org', 'path' => '/etc/php.ini', ] ], [ 'file:///etc/php.ini', [ 'scheme' => 'file', 'delimiter' => '://', 'host' => '', 'path' => '/etc/php.ini', ] ], [ 'file:///c:/', [ 'scheme' => 'file', 'delimiter' => '://', 'host' => '', 'path' => '/c:/', ] ], [ 'mailto:id@example.org', [ 'scheme' => 'mailto', 'delimiter' => ':', 'host' => 'id@example.org', 'path' => '', ] ], [ 'mailto:id@example.org?subject=Foo', [ 'scheme' => 'mailto', 'delimiter' => ':', 'host' => 'id@example.org', 'path' => '', 'query' => 'subject=Foo', ] ], [ 'mailto:?subject=Foo', [ 'scheme' => 'mailto', 'delimiter' => ':', 'host' => '', 'path' => '', 'query' => 'subject=Foo', ] ], [ 'invalid://test/', false ], // T212067 [ '//evil.com?example.org/foo/bar', [ 'scheme' => '', 'delimiter' => '//', 'host' => 'evil.com', 'query' => 'example.org/foo/bar', ] ], [ '//evil.com?example.org/foo/bar?baz#quux', [ 'scheme' => '', 'delimiter' => '//', 'host' => 'evil.com', 'query' => 'example.org/foo/bar?baz', 'fragment' => 'quux', ] ], [ '//evil.com?example.org?baz#quux', [ 'scheme' => '', 'delimiter' => '//', 'host' => 'evil.com', 'query' => 'example.org?baz', 'fragment' => 'quux', ] ], [ '//evil.com?example.org#quux', [ 'scheme' => '', 'delimiter' => '//', 'host' => 'evil.com', 'query' => 'example.org', 'fragment' => 'quux', ] ], ]; } }