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
6 changes: 3 additions & 3 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4509,10 +4509,10 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) {
/*
* If the URL doesn't appear to contain a scheme, we presume
* it needs http:// prepended (unless it's a relative link
* starting with /, # or ?, or a PHP file). If the first item
* in $protocols is 'https', then https:// is prepended.
* starting with ., /, # or ?, or a PHP file). If the first
* item in $protocols is 'https', then https:// is prepended.
*/
if ( ! str_contains( $url, ':' ) && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
if ( ! str_contains( $url, ':' ) && ! in_array( $url[0], array( '.', '/', '#', '?' ), true ) &&
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have but in core do we use similar pattern for retrieve the path?

! preg_match( '/^[a-z0-9-]+?\.php/i', $url )
) {
$scheme = ( is_array( $protocols ) && 'https' === array_first( $protocols ) ) ? 'https://' : 'http://';
Expand Down
9 changes: 9 additions & 0 deletions tests/phpunit/tests/formatting/escUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,13 @@ 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' ) );
}

/**
* @ticket 46791
*/
public function test_directory_relative_references() {
$this->assertSame( './current-directory', esc_url( './current-directory' ) );
$this->assertSame( '../parent-directory', esc_url( '../parent-directory' ) );
$this->assertSame( '../../../../up-four-directories', esc_url( '../../../../up-four-directories' ) );
}
}
Loading