From dd9722fac06e16d12f0780883c52d6b8651f3717 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 5 Sep 2015 21:28:50 +0000 Subject: [PATCH] Bail out early from `esc_url()` if the URL becomes empty after stripping out disallowed characters. Fixes #28015 Props jesin for the unit test git-svn-id: https://develop.svn.wordpress.org/trunk@33923 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 5 +++++ tests/phpunit/tests/formatting/EscUrl.php | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 29f67fedb9..be8ea6c994 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3277,6 +3277,11 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) { $url = str_replace( ' ', '%20', $url ); $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url); + + if ( '' === $url ) { + return $url; + } + if ( 0 !== stripos( $url, 'mailto:' ) ) { $strip = array('%0d', '%0a', '%0D', '%0A'); $url = _deep_replace($strip, $url); diff --git a/tests/phpunit/tests/formatting/EscUrl.php b/tests/phpunit/tests/formatting/EscUrl.php index c61522d287..1289fd7c76 100644 --- a/tests/phpunit/tests/formatting/EscUrl.php +++ b/tests/phpunit/tests/formatting/EscUrl.php @@ -171,5 +171,11 @@ EOT; $this->assertEquals( 'mailto:?body=Hi%20there,%20I%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link ); } + /** + * @ticket 28015 + */ + function test_invalid_charaters() { + $this->assertEmpty( esc_url_raw('"^[]<>{}`') ); + } }