Formatting: Trim leading whitespace in `esc_url()`.

Props toszcze.
Fixes #36369.



git-svn-id: https://develop.svn.wordpress.org/trunk@45578 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-07-01 03:28:21 +00:00
parent 77f9bf0aeb
commit 78e096fe98
2 changed files with 2 additions and 1 deletions

View File

@ -4202,7 +4202,7 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) {
return $url;
}
$url = str_replace( ' ', '%20', $url );
$url = str_replace( ' ', '%20', ltrim( $url ) );
$url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url );
if ( '' === $url ) {

View File

@ -13,6 +13,7 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase {
$this->assertEquals( 'http://example.com/Mr%20WordPress', esc_url( 'http://example.com/Mr%20WordPress' ) );
$this->assertEquals( 'http://example.com/Mr%20%20WordPress', esc_url( 'http://example.com/Mr%20%20WordPress' ) );
$this->assertEquals( 'http://example.com/Mr+WordPress', esc_url( 'http://example.com/Mr+WordPress' ) );
$this->assertEquals( 'http://example.com/Mr+WordPress', esc_url( ' http://example.com/Mr+WordPress' ) );
$this->assertEquals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one two three&bar=four' ) );
$this->assertEquals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one%20two%20three&bar=four' ) );