Make WordPress Core


Ignore:
Timestamp:
07/03/2015 02:27:11 PM (9 years ago)
Author:
jorbin
Message:

Don't strip newline in esc_url() when protocol is mailto:

The mailto protocol is a bit different than the other protocols in that new lines are something you might realistically want to include. Includes tests to make sure that http protocol urls that contain mailto: aren't affected. Tests for stripping newlines in general already exist.

Fixes #31632
Props danielbachhuber

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/EscUrl.php

    r30514 r33064  
    6969        $this->assertEquals( '//example.com/foo?foo=abc:def', esc_url( '//example.com/foo?foo=abc:def' ) );
    7070    }
     71
     72    /**
     73     * @ticket 31632
     74     */
     75    function test_mailto_with_newline() {
     76        $body = <<<EOT
     77Hi there,
     78
     79I thought you might want to sign up for this newsletter
     80EOT;
     81        $email_link = 'mailto:?body=' . rawurlencode( $body );
     82        $email_link = esc_url( $email_link );
     83        $this->assertEquals( 'mailto:?body=Hi%20there%2C%0A%0AI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );
     84    }
     85    /**
     86     * @ticket 31632
     87     */
     88    function test_mailto_in_http_url_with_newline() {
     89        $body = <<<EOT
     90Hi there,
     91
     92I thought you might want to sign up for this newsletter
     93EOT;
     94        $email_link = 'http://example.com/mailto:?body=' . rawurlencode( $body );
     95        $email_link = esc_url( $email_link );
     96        $this->assertEquals( 'http://example.com/mailto:?body=Hi%20there%2CI%20thought%20you%20might%20want%20to%20sign%20up%20for%20this%20newsletter', $email_link );
     97    }
     98
    7199}
Note: See TracChangeset for help on using the changeset viewer.