diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index c56d82017e..27d64e1dc6 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3770,11 +3770,13 @@ function wp_unslash( $value ) { * @return string The found URL. */ function get_url_in_content( $content ) { - if ( empty( $content ) ) - return ''; + if ( empty( $content ) ) { + return false; + } - if ( preg_match( '/]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) + if ( preg_match( '/]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) { return esc_url_raw( $matches[2] ); + } return false; } diff --git a/tests/phpunit/tests/formatting/GetUrlInContent.php b/tests/phpunit/tests/formatting/GetUrlInContent.php new file mode 100644 index 0000000000..f34bdd855f --- /dev/null +++ b/tests/phpunit/tests/formatting/GetUrlInContent.php @@ -0,0 +1,49 @@ +NO URL CONTENT", + false + ), //no URLs + array ( + '
NO URL CONTENT
', + false + ), // ignore none link elements + array ( + 'ABC
LINK CONTENT
', + "/relative.php" + ), // single link + array ( + 'ABC
LINK CONTENT LINK
', + "/relative.php" + ), // multiple links + array ( + 'ABC
LINK CONTENT
', + "http://example.com/Mr%20WordPress2" + ), // escape link + ); + } + + /** + * Validate the get_url_in_content function + * @dataProvider get_input_output + */ + function test_get_url_in_content( $in_str, $exp_str ) { + $this->assertEquals($exp_str, get_url_in_content( $in_str ) ); + } +}