X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FLinkFilterTest.php;h=428b0129a0d9e3bbb877cc5bbcdeceb685e366f8;hb=34fe90ac52644c3a543ca8adf89900c0fb2de70b;hp=f011f47ccb910bbbb8c79ed8e4e22e6cf1d83bf6;hpb=8d1c5a70f753fe6b7d2533a30b07fe03e6583a1d;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/LinkFilterTest.php b/tests/phpunit/includes/LinkFilterTest.php index f011f47ccb..428b0129a0 100644 --- a/tests/phpunit/includes/LinkFilterTest.php +++ b/tests/phpunit/includes/LinkFilterTest.php @@ -6,10 +6,9 @@ class LinkFilterTest extends MediaWikiLangTestCase { protected function setUp() { - parent::setUp(); - $this->setMwGlobals( 'wgUrlProtocols', array( + $this->setMwGlobals( 'wgUrlProtocols', [ 'http://', 'https://', 'ftp://', @@ -25,8 +24,7 @@ class LinkFilterTest extends MediaWikiLangTestCase { 'git://', 'mms://', '//', - ) ); - + ] ); } /** @@ -38,11 +36,9 @@ class LinkFilterTest extends MediaWikiLangTestCase { * @return string Regex */ function createRegexFromLIKE( $like ) { - $regex = '!^'; foreach ( $like as $item ) { - if ( $item instanceof LikeMatch ) { if ( $item->toString() == '%' ) { $regex .= '.*'; @@ -58,7 +54,6 @@ class LinkFilterTest extends MediaWikiLangTestCase { $regex .= '$!'; return $regex; - } /** @@ -67,114 +62,102 @@ class LinkFilterTest extends MediaWikiLangTestCase { * @return array */ public static function provideValidPatterns() { - - return array( + return [ // Protocol, Search pattern, URL which matches the pattern - array( 'http://', '*.test.com', 'http://www.test.com' ), - array( 'http://', 'test.com:8080/dir/file', 'http://name:pass@test.com:8080/dir/file' ), - array( 'https://', '*.com', 'https://s.s.test..com:88/dir/file?a=1&b=2' ), - array( 'https://', '*.com', 'https://name:pass@secure.com/index.html' ), - array( 'http://', 'name:pass@test.com', 'http://test.com' ), - array( 'http://', 'test.com', 'http://name:pass@test.com' ), - array( 'http://', '*.test.com', 'http://a.b.c.test.com/dir/dir/file?a=6' ), - array( null, 'http://*.test.com', 'http://www.test.com' ), - array( 'mailto:', 'name@mail.test123.com', 'mailto:name@mail.test123.com' ), - array( '', + [ 'http://', '*.test.com', 'http://www.test.com' ], + [ 'http://', 'test.com:8080/dir/file', 'http://name:pass@test.com:8080/dir/file' ], + [ 'https://', '*.com', 'https://s.s.test..com:88/dir/file?a=1&b=2' ], + [ 'https://', '*.com', 'https://name:pass@secure.com/index.html' ], + [ 'http://', 'name:pass@test.com', 'http://test.com' ], + [ 'http://', 'test.com', 'http://name:pass@test.com' ], + [ 'http://', '*.test.com', 'http://a.b.c.test.com/dir/dir/file?a=6' ], + [ null, 'http://*.test.com', 'http://www.test.com' ], + [ 'mailto:', 'name@mail.test123.com', 'mailto:name@mail.test123.com' ], + [ '', 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg', 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' - ), - array( '', 'http://name:pass@*.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg', - 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ), - array( '', 'http://name:wrongpass@*.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]', - 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ), - array( 'http://', 'name:pass@*.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg', - 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ), - array( '', 'http://name:pass@www.test.com:12345', - 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ), - array( 'ftp://', 'user:pass@ftp.test.com:1233/home/user/file;type=efw', - 'ftp://user:pass@ftp.test.com:1233/home/user/file;type=efw' ), - array( null, 'ftp://otheruser:otherpass@ftp.test.com:1233/home/user/file;type=', - 'ftp://user:pass@ftp.test.com:1233/home/user/file;type=efw' ), - array( null, 'ftp://@ftp.test.com:1233/home/user/file;type=', - 'ftp://user:pass@ftp.test.com:1233/home/user/file;type=efw' ), - array( null, 'ftp://ftp.test.com/', - 'ftp://user:pass@ftp.test.com/home/user/file;type=efw' ), - array( null, 'ftp://ftp.test.com/', - 'ftp://user:pass@ftp.test.com/home/user/file;type=efw' ), - array( null, 'ftp://*.test.com:222/', - 'ftp://user:pass@ftp.test.com:222/home' ), - array( 'irc://', '*.myserver:6667/', 'irc://test.myserver:6667/' ), - array( 'irc://', 'name:pass@*.myserver/', 'irc://test.myserver:6667/' ), - array( 'irc://', 'name:pass@*.myserver/', 'irc://other:@test.myserver:6667/' ), - array( '', 'irc://test/name,string,abc?msg=t', 'irc://test/name,string,abc?msg=test' ), - array( '', 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z', - 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z' ), - array( '', 'https://gerrit.wikimedia.org', - 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z' ), - array( 'mailto:', '*.test.com', 'mailto:name@pop3.test.com' ), - array( 'mailto:', 'test.com', 'mailto:name@test.com' ), - array( 'news:', 'test.1234afc@news.test.com', 'news:test.1234afc@news.test.com' ), - array( 'news:', '*.test.com', 'news:test.1234afc@news.test.com' ), - array( '', 'news:4df8kh$iagfewewf(at)newsbf02aaa.news.aol.com', - 'news:4df8kh$iagfewewf(at)newsbf02aaa.news.aol.com' ), - array( '', 'news:*.aol.com', - 'news:4df8kh$iagfewewf(at)newsbf02aaa.news.aol.com' ), - array( '', 'git://github.com/prwef/abc-def.git', 'git://github.com/prwef/abc-def.git' ), - array( 'git://', 'github.com/', 'git://github.com/prwef/abc-def.git' ), - array( 'git://', '*.github.com/', 'git://a.b.c.d.e.f.github.com/prwef/abc-def.git' ), - array( '', 'gopher://*.test.com/', 'gopher://gopher.test.com/0/v2/vstat' ), - array( 'telnet://', '*.test.com', 'telnet://shell.test.com/~home/' ), - - // - // The following only work in PHP >= 5.3.7, due to a bug in parse_url which eats - // the path from the url (https://bugs.php.net/bug.php?id=54180) - // - // array( '', 'http://test.com', 'http://test.com/index?arg=1' ), - // array( 'http://', '*.test.com', 'http://www.test.com/index?arg=1' ), - // array( '' , - // 'http://xx23124:__ffdfdef__@www.test.com:12345/dir' , - // 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' - // ), - // + ], + [ '', 'http://name:pass@*.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg', + 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ], + [ '', 'http://name:wrongpass@*.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]', + 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ], + [ 'http://', 'name:pass@*.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg', + 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ], + [ '', 'http://name:pass@www.test.com:12345', + 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' ], + [ 'ftp://', 'user:pass@ftp.test.com:1233/home/user/file;type=efw', + 'ftp://user:pass@ftp.test.com:1233/home/user/file;type=efw' ], + [ null, 'ftp://otheruser:otherpass@ftp.test.com:1233/home/user/file;type=', + 'ftp://user:pass@ftp.test.com:1233/home/user/file;type=efw' ], + [ null, 'ftp://@ftp.test.com:1233/home/user/file;type=', + 'ftp://user:pass@ftp.test.com:1233/home/user/file;type=efw' ], + [ null, 'ftp://ftp.test.com/', + 'ftp://user:pass@ftp.test.com/home/user/file;type=efw' ], + [ null, 'ftp://ftp.test.com/', + 'ftp://user:pass@ftp.test.com/home/user/file;type=efw' ], + [ null, 'ftp://*.test.com:222/', + 'ftp://user:pass@ftp.test.com:222/home' ], + [ 'irc://', '*.myserver:6667/', 'irc://test.myserver:6667/' ], + [ 'irc://', 'name:pass@*.myserver/', 'irc://test.myserver:6667/' ], + [ 'irc://', 'name:pass@*.myserver/', 'irc://other:@test.myserver:6667/' ], + [ '', 'irc://test/name,string,abc?msg=t', 'irc://test/name,string,abc?msg=test' ], + [ '', 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z', + 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z' ], + [ '', 'https://gerrit.wikimedia.org', + 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z' ], + [ 'mailto:', '*.test.com', 'mailto:name@pop3.test.com' ], + [ 'mailto:', 'test.com', 'mailto:name@test.com' ], + [ 'news:', 'test.1234afc@news.test.com', 'news:test.1234afc@news.test.com' ], + [ 'news:', '*.test.com', 'news:test.1234afc@news.test.com' ], + [ '', 'news:4df8kh$iagfewewf(at)newsbf02aaa.news.aol.com', + 'news:4df8kh$iagfewewf(at)newsbf02aaa.news.aol.com' ], + [ '', 'news:*.aol.com', + 'news:4df8kh$iagfewewf(at)newsbf02aaa.news.aol.com' ], + [ '', 'git://github.com/prwef/abc-def.git', 'git://github.com/prwef/abc-def.git' ], + [ 'git://', 'github.com/', 'git://github.com/prwef/abc-def.git' ], + [ 'git://', '*.github.com/', 'git://a.b.c.d.e.f.github.com/prwef/abc-def.git' ], + [ '', 'gopher://*.test.com/', 'gopher://gopher.test.com/0/v2/vstat' ], + [ 'telnet://', '*.test.com', 'telnet://shell.test.com/~home/' ], + [ '', 'http://test.com', 'http://test.com/index?arg=1' ], + [ 'http://', '*.test.com', 'http://www.test.com/index?arg=1' ], + [ '' , + 'http://xx23124:__ffdfdef__@www.test.com:12345/dir' , + 'http://name:pass@www.test.com:12345/dir/dir/file.xyz.php#__se__?arg1=_&arg2[]=4rtg' + ], - // // Tests for false positives - // - array( 'http://', 'test.com', 'http://www.test.com', false ), - array( 'http://', 'www1.test.com', 'http://www.test.com', false ), - array( 'http://', '*.test.com', 'http://www.test.t.com', false ), - array( '', 'http://test.com:8080', 'http://www.test.com:8080', false ), - array( '', 'https://test.com', 'http://test.com', false ), - array( '', 'http://test.com', 'https://test.com', false ), - array( 'http://', 'http://test.com', 'http://test.com', false ), - array( null, 'http://www.test.com', 'http://www.test.com:80', false ), - array( null, 'http://www.test.com:80', 'http://www.test.com', false ), - array( null, 'http://*.test.com:80', 'http://www.test.com', false ), - array( '', 'https://gerrit.wikimedia.org/r/#/XXX/status:open,n,z', - 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z', false ), - array( '', 'https://*.wikimedia.org/r/#/q/status:open,n,z', - 'https://gerrit.wikimedia.org/r/#/XXX/status:open,n,z', false ), - array( 'mailto:', '@test.com', '@abc.test.com', false ), - array( 'mailto:', 'mail@test.com', 'mail2@test.com', false ), - array( '', 'mailto:mail@test.com', 'mail2@test.com', false ), - array( '', 'mailto:@test.com', '@abc.test.com', false ), - array( 'ftp://', '*.co', 'ftp://www.co.uk', false ), - array( 'ftp://', '*.co', 'ftp://www.co.m', false ), - array( 'ftp://', '*.co/dir/', 'ftp://www.co/dir2/', false ), - array( 'ftp://', 'www.co/dir/', 'ftp://www.co/dir2/', false ), - array( 'ftp://', 'test.com/dir/', 'ftp://test.com/', false ), - array( '', 'http://test.com:8080/dir/', 'http://test.com:808/dir/', false ), - array( '', 'http://test.com/dir/index.html', 'http://test.com/dir/index.php', false ), + [ 'http://', 'test.com', 'http://www.test.com', false ], + [ 'http://', 'www1.test.com', 'http://www.test.com', false ], + [ 'http://', '*.test.com', 'http://www.test.t.com', false ], + [ '', 'http://test.com:8080', 'http://www.test.com:8080', false ], + [ '', 'https://test.com', 'http://test.com', false ], + [ '', 'http://test.com', 'https://test.com', false ], + [ 'http://', 'http://test.com', 'http://test.com', false ], + [ null, 'http://www.test.com', 'http://www.test.com:80', false ], + [ null, 'http://www.test.com:80', 'http://www.test.com', false ], + [ null, 'http://*.test.com:80', 'http://www.test.com', false ], + [ '', 'https://gerrit.wikimedia.org/r/#/XXX/status:open,n,z', + 'https://gerrit.wikimedia.org/r/#/q/status:open,n,z', false ], + [ '', 'https://*.wikimedia.org/r/#/q/status:open,n,z', + 'https://gerrit.wikimedia.org/r/#/XXX/status:open,n,z', false ], + [ 'mailto:', '@test.com', '@abc.test.com', false ], + [ 'mailto:', 'mail@test.com', 'mail2@test.com', false ], + [ '', 'mailto:mail@test.com', 'mail2@test.com', false ], + [ '', 'mailto:@test.com', '@abc.test.com', false ], + [ 'ftp://', '*.co', 'ftp://www.co.uk', false ], + [ 'ftp://', '*.co', 'ftp://www.co.m', false ], + [ 'ftp://', '*.co/dir/', 'ftp://www.co/dir2/', false ], + [ 'ftp://', 'www.co/dir/', 'ftp://www.co/dir2/', false ], + [ 'ftp://', 'test.com/dir/', 'ftp://test.com/', false ], + [ '', 'http://test.com:8080/dir/', 'http://test.com:808/dir/', false ], + [ '', 'http://test.com/dir/index.html', 'http://test.com/dir/index.php', false ], - // // These are false positives too and ideally shouldn't match, but that // would require using regexes and RLIKE instead of LIKE - // - // array( null, 'http://*.test.com', 'http://www.test.com:80', false ), - // array( '', 'https://*.wikimedia.org/r/#/q/status:open,n,z', - // 'https://gerrit.wikimedia.org/XXX/r/#/q/status:open,n,z', false ), - ); - + // [ null, 'http://*.test.com', 'http://www.test.com:80', false ], + // [ '', 'https://*.wikimedia.org/r/#/q/status:open,n,z', + // 'https://gerrit.wikimedia.org/XXX/r/#/q/status:open,n,z', false ], + ]; } /** @@ -191,7 +174,6 @@ class LinkFilterTest extends MediaWikiLangTestCase { * @param bool $shouldBeFound Should the URL be found? (defaults true) */ function testMakeLikeArrayWithValidPatterns( $protocol, $pattern, $url, $shouldBeFound = true ) { - $indexes = wfMakeUrlIndexes( $url ); $likeArray = LinkFilter::makeLikeArray( $pattern, $protocol ); @@ -221,7 +203,6 @@ class LinkFilterTest extends MediaWikiLangTestCase { "Search pattern '$protocol$pattern' should not find url '$url' \n$debugmsg" ); } - } /** @@ -230,27 +211,25 @@ class LinkFilterTest extends MediaWikiLangTestCase { * @return array */ public static function provideInvalidPatterns() { - - return array( - array( '' ), - array( '*' ), - array( 'http://*' ), - array( 'http://*/' ), - array( 'http://*/dir/file' ), - array( 'test.*.com' ), - array( 'http://test.*.com' ), - array( 'test.*.com' ), - array( 'http://*.test.*' ), - array( 'http://*test.com' ), - array( 'https://*' ), - array( '*://test.com' ), - array( 'mailto:name:pass@t*est.com' ), - array( 'http://*:888/' ), - array( '*http://' ), - array( 'test.com/*/index' ), - array( 'test.com/dir/index?arg=*' ), - ); - + return [ + [ '' ], + [ '*' ], + [ 'http://*' ], + [ 'http://*/' ], + [ 'http://*/dir/file' ], + [ 'test.*.com' ], + [ 'http://test.*.com' ], + [ 'test.*.com' ], + [ 'http://*.test.*' ], + [ 'http://*test.com' ], + [ 'https://*' ], + [ '*://test.com' ], + [ 'mailto:name:pass@t*est.com' ], + [ 'http://*:888/' ], + [ '*http://' ], + [ 'test.com/*/index' ], + [ 'test.com/dir/index?arg=*' ], + ]; } /** @@ -263,12 +242,10 @@ class LinkFilterTest extends MediaWikiLangTestCase { * @param string $pattern Invalid search pattern */ function testMakeLikeArrayWithInvalidPatterns( $pattern ) { - $this->assertFalse( LinkFilter::makeLikeArray( $pattern ), "'$pattern' is not a valid pattern and should be rejected" ); - } }