Use `wp_parse_url()` in `esc_url()` to avoid parsing bugs in < PHP 5.4.7.

Props johnbillion for unit tests
See #34408
Fixes #34202


git-svn-id: https://develop.svn.wordpress.org/trunk@35370 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2015-10-23 05:56:25 +00:00
parent cacd015856
commit 8c33fe770e
2 changed files with 15 additions and 1 deletions

View File

@ -3398,7 +3398,7 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) {
if ( ( false !== strpos( $url, '[' ) ) || ( false !== strpos( $url, ']' ) ) ) {
$parsed = parse_url( $url );
$parsed = wp_parse_url( $url );
$front = '';
if ( isset( $parsed['scheme'] ) ) {

View File

@ -210,4 +210,18 @@ EOT;
$this->assertEmpty( esc_url_raw('"^<>{}`') );
}
/**
* @ticket 34202
*/
function test_ipv6_hosts() {
$this->assertEquals( '//[::127.0.0.1]', esc_url( '//[::127.0.0.1]' ) );
$this->assertEquals( 'http://[::FFFF::127.0.0.1]', esc_url( 'http://[::FFFF::127.0.0.1]' ) );
$this->assertEquals( 'http://[::127.0.0.1]', esc_url( 'http://[::127.0.0.1]' ) );
$this->assertEquals( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]', esc_url( 'http://[::DEAD:BEEF:DEAD:BEEF:DEAD:BEEF:DEAD:BEEF]' ) );
// IPv6 with square brackets in the query? Why not.
$this->assertEquals( '//[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( '//[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );
$this->assertEquals( 'http://[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( 'http://[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );
}
}