Make WordPress Core

Changeset 33858


Ignore:
Timestamp:
09/02/2015 05:19:29 PM (11 years ago)
Author:
johnbillion
Message:

Correctly encode spaces in URLs passed to esc_url() instead of removing them.

Fixes #23605
Props enshrined, johnbillion

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r33734 r33858  
    32753275        if ( '' == $url )
    32763276                return $url;
     3277
     3278        $url = str_replace( ' ', '%20', $url );
    32773279        $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
    32783280        if ( 0 !== stripos( $url, 'mailto:' ) ) {
     
    32803282                $url = _deep_replace($strip, $url);
    32813283        }
     3284
    32823285        $url = str_replace(';//', '://', $url);
    32833286        /* If the URL doesn't appear to contain a scheme, we
  • trunk/tests/phpunit/tests/formatting/EscUrl.php

    r33855 r33858  
    55 */
    66class Tests_Formatting_EscUrl extends WP_UnitTestCase {
     7
     8        /**
     9         * @ticket 23605
     10         */
    711        function test_spaces() {
    8                 $this->assertEquals('http://example.com/MrWordPress', esc_url('http://example.com/Mr WordPress'));
    9                 $this->assertEquals('http://example.com/Mr%20WordPress', esc_url('http://example.com/Mr%20WordPress'));
     12                $this->assertEquals( 'http://example.com/Mr%20WordPress',    esc_url( 'http://example.com/Mr WordPress' ) );
     13                $this->assertEquals( 'http://example.com/Mr%20WordPress',    esc_url( 'http://example.com/Mr%20WordPress' ) );
     14                $this->assertEquals( 'http://example.com/Mr%20%20WordPress', esc_url( 'http://example.com/Mr%20%20WordPress' ) );
     15                $this->assertEquals( 'http://example.com/Mr+WordPress',      esc_url( 'http://example.com/Mr+WordPress' ) );
     16
     17                $this->assertEquals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one two three&bar=four' ) );
     18                $this->assertEquals( 'http://example.com/?foo=one%20two%20three&bar=four', esc_url( 'http://example.com/?foo=one%20two%20three&bar=four' ) );
    1019        }
    1120
     
    137146                $this->assertEquals( 'mailto:?body=Hi%20there%2C%0A%0AI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );
    138147        }
     148
    139149        /**
    140150         * @ticket 31632
     
    151161        }
    152162
     163        /**
     164         * @ticket 23605
     165         */
     166        function test_mailto_with_spaces() {
     167                $body = 'Hi there, I thought you might want to sign up for this newsletter';
     168
     169                $email_link = 'mailto:?body=' . $body;
     170                $email_link = esc_url( $email_link );
     171                $this->assertEquals( 'mailto:?body=Hi%20there,%20I%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );
     172        }
     173
     174
    153175}
Note: See TracChangeset for help on using the changeset viewer.