Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4538,8 +4538,8 @@ function esc_sql( $data ) {
function esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;

if ( '' === $url ) {
return $url;
if ( '' === $url || null === $url ) {
return '';
}

$url = str_replace( ' ', '%20', ltrim( $url ) );
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/formatting/escUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,26 @@ public function test_ipv6_hosts() {
$this->assertSame( '//[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( '//[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );
$this->assertSame( 'http://[::FFFF::127.0.0.1]/?foo%5Bbar%5D=baz', esc_url( 'http://[::FFFF::127.0.0.1]/?foo[bar]=baz' ) );
}

/**
* Test that esc_url() handles null input without triggering
* a PHP 8.1 "passing null to non-nullable" deprecation.
*
* @ticket 65432
*/
public function test_null_input_returns_empty_string() {
$this->assertSame( '', esc_url( null ) );
}

/**
* Test that sanitize_url() handles null input without triggering
* a PHP 8.1 "passing null to non-nullable" deprecation.
*
* @ticket 65432
*
* @covers ::sanitize_url
*/
public function test_sanitize_url_null_input_returns_empty_string() {
$this->assertSame( '', sanitize_url( null ) );
}
}
Loading