From f00f28cce0bc73a7d633682ed661baf36afade41 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 23 Sep 2014 02:49:22 +0000 Subject: [PATCH] `wp_extract_urls()` needs to also grab URLs with query strings and hashes. Updates unit test. Props hauvong, dlh. Fixes #29314. git-svn-id: https://develop.svn.wordpress.org/trunk@29756 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 8 ++++---- tests/phpunit/tests/functions.php | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 0a8e1a0ccc..b164d92c6d 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -457,23 +457,23 @@ function xmlrpc_removepostdata( $content ) { */ function wp_extract_urls( $content ) { preg_match_all( - "#(" + "#([\"']?)(" . "(?:([\w-]+:)?//?)" . "[^\s()<>]+" . "[.]" . "(?:" . "\([\w\d]+\)|" . "(?:" - . "[^`!()\[\]{};:'\".,<>?«»“”‘’\s]|" + . "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|" . "(?:[:]\d+)?/?" . ")+" . ")" - . ")#", + . ")\\1#", $content, $post_links ); - $post_links = array_unique( array_map( 'html_entity_decode', $post_links[0] ) ); + $post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) ); return array_values( $post_links ); } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 6d7f972cf3..a44d2b62fb 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -421,7 +421,9 @@ class Tests_Functions extends WP_UnitTestCase { 'http://türkiye.icom.museum', 'http://украина.icom.museum', 'http://việtnam.icom.museum', - 'ftp://127.0.0.1/' + 'ftp://127.0.0.1/', + 'http://www.woo.com/video?v=exvUH2qKLTU', + 'http://taco.com?burrito=enchilada#guac' ); $blob =" @@ -481,6 +483,9 @@ class Tests_Functions extends WP_UnitTestCase { http://украина.icom.museum http://việtnam.icom.museum ftp://127.0.0.1/ + http://www.woo.com/video?v=exvUH2qKLTU + + http://taco.com?burrito=enchilada#guac "; $urls = wp_extract_urls( $blob );