wp_extract_urls() should not match dates.

Updates unit tests.

Props hinnerk, sergej.mueller.
Fixes #28222.


git-svn-id: https://develop.svn.wordpress.org/trunk@28882 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-28 04:15:30 +00:00
parent dca6040b0b
commit 56e66c79b4
2 changed files with 24 additions and 8 deletions

View File

@ -441,7 +441,18 @@ function xmlrpc_removepostdata( $content ) {
*/
function wp_extract_urls( $content ) {
preg_match_all(
"#((?:[\w-]+://?|[\w\d]+[.])[^\s()<>]+[.](?:\([\w\d]+\)|(?:[^`!()\[\]{};:'\".,<>?«»“”‘’\s]|(?:[:]\d+)?/?)+))#",
"#("
. "(?: ([\w-]+:)?//? )"
. "[^\s()<>]+"
. "[.]"
. "(?:"
. "\([\w\d]+\) |"
. "(?:"
. "[^`!()\[\]{};:'\".,<>?«»“”‘’\s] |"
. "(?: [:]\d+ )?/?"
. ")+"
. ")"
. ")#x",
$content,
$post_links
);

View File

@ -370,6 +370,7 @@ class Tests_Functions extends WP_UnitTestCase {
$original_urls = array(
'http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html',
'http://this.com',
'http://127.0.0.1',
'http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&2134362574863.437',
'http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html',
'http://wordpress-core.com:8080/',
@ -419,7 +420,8 @@ class Tests_Functions extends WP_UnitTestCase {
'http://تونس.icom.museum',
'http://türkiye.icom.museum',
'http://украина.icom.museum',
'http://việtnam.icom.museum'
'http://việtnam.icom.museum',
'ftp://127.0.0.1/'
);
$blob ="
@ -427,6 +429,8 @@ class Tests_Functions extends WP_UnitTestCase {
http://this.com
http://127.0.0.1
http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&amp;2134362574863.437
http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html
@ -476,6 +480,7 @@ class Tests_Functions extends WP_UnitTestCase {
http://türkiye.icom.museum
http://украина.icom.museum
http://việtnam.icom.museum
ftp://127.0.0.1/
";
$urls = wp_extract_urls( $blob );
@ -493,7 +498,7 @@ class Tests_Functions extends WP_UnitTestCase {
$blob ="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html et dolore magna aliqua.
Ut http://this.com enim ad minim veniam, quis nostrud exercitation ullamco
Ut http://this.com enim ad minim veniam, quis nostrud exercitation 16.06. to 18.06.2014 ullamco http://127.0.0.1
laboris nisi ut aliquip ex http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&amp;2134362574863.437 ea
commodo consequat. http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html Duis aute irure dolor in reprehenderit in voluptate
velit esse http://wordpress-core.com:8080/ cillum dolore eu fugiat nulla <A href=\"http://www.website.com:5000\">http://www.website.com:5000</B> pariatur. Excepteur sint occaecat cupidatat non proident,
@ -502,12 +507,12 @@ class Tests_Functions extends WP_UnitTestCase {
$urls = wp_extract_urls( $blob );
$this->assertNotEmpty( $urls );
$this->assertInternalType( 'array', $urls );
$this->assertCount( 7, $urls );
$this->assertEquals( array_slice( $original_urls, 0, 7 ), $urls );
$this->assertCount( 8, $urls );
$this->assertEquals( array_slice( $original_urls, 0, 8 ), $urls );
$blob = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore <a href="http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html">343462^</a> et dolore magna aliqua.
Ut <a href="http://this.com">&amp;3640i6p1yi499</a> enim ad minim veniam, quis nostrud exercitation ullamco
Ut <a href="http://this.com">&amp;3640i6p1yi499</a> enim ad minim veniam, quis nostrud exercitation 16.06. to 18.06.2014 ullamco <a href="http://127.0.0.1">localhost</a>
laboris nisi ut aliquip ex <a href="http://www111.urwyeoweytwutreyytqytwetowteuiiu.com/?346236346326&amp;2134362574863.437">343462^</a> ea
commodo consequat. <a href="http://wordpress-core/1,2,3,4,5,6/-1-2-3-4-/woo.html">343462^</a> Duis aute irure dolor in reprehenderit in voluptate
velit esse <a href="http://wordpress-core.com:8080/">-3-4--321-64-4@#!$^$!@^@^</a> cillum dolore eu <A href="http://www.website.com:5000">http://www.website.com:5000</B> fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
@ -516,7 +521,7 @@ class Tests_Functions extends WP_UnitTestCase {
$urls = wp_extract_urls( $blob );
$this->assertNotEmpty( $urls );
$this->assertInternalType( 'array', $urls );
$this->assertCount( 7, $urls );
$this->assertEquals( array_slice( $original_urls, 0, 7 ), $urls );
$this->assertCount( 8, $urls );
$this->assertEquals( array_slice( $original_urls, 0, 8 ), $urls );
}
}