From 56e66c79b46f64471e9a0cbc5b8d29bbea15b417 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 28 Jun 2014 04:15:30 +0000 Subject: [PATCH] `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 --- src/wp-includes/functions.php | 13 ++++++++++++- tests/phpunit/tests/functions.php | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index bc8135a1b4..d238e3c0b9 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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 ); diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index a223cf439a..caac87492a 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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&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&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 http://www.website.com:5000 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 343462^ et dolore magna aliqua. - Ut &3640i6p1yi499 enim ad minim veniam, quis nostrud exercitation ullamco + Ut &3640i6p1yi499 enim ad minim veniam, quis nostrud exercitation 16.06. to 18.06.2014 ullamco localhost laboris nisi ut aliquip ex 343462^ ea commodo consequat. 343462^ Duis aute irure dolor in reprehenderit in voluptate velit esse -3-4--321-64-4@#!$^$!@^@^ cillum dolore eu http://www.website.com:5000 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 ); } }