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
7 changes: 4 additions & 3 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2153,9 +2153,10 @@ function wp_mkdir_p( $target ) {
/**
* Tests if a given filesystem path is absolute.
*
* For example, '/foo/bar', or 'c:\windows'.
* For example, '/foo/bar', 'c:\windows', or 'c:/windows'.
*
* @since 2.5.0
* @since 7.2.0 Windows drive-letter paths using forward slashes are now recognized as absolute.
*
* @param string $path File path.
* @return bool True if path is absolute, false is not absolute.
Expand Down Expand Up @@ -2184,8 +2185,8 @@ function path_is_absolute( $path ) {
return false;
}

// Windows allows absolute paths like this.
if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
// Windows allows absolute paths like this, with either separator.
if ( preg_match( '#^[a-zA-Z]:[\\\\/]#', $path ) ) {
return true;
}

Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,45 @@ public function test_path_is_absolute() {
}
}

/**
* Tests that Windows drive-letter paths using forward slashes are absolute.
*
* @ticket 48289
* @covers ::path_is_absolute
* @dataProvider data_path_is_absolute_windows_forward_slashes
*
* @param string $path Path to test.
*/
public function test_path_is_absolute_accepts_windows_drive_path_with_forward_slashes( $path ) {
$this->assertTrue( path_is_absolute( $path ), "path_is_absolute('$path') should return true" );
}

/**
* Data provider for test_path_is_absolute_accepts_windows_drive_path_with_forward_slashes().
*
* @return array[]
*/
public function data_path_is_absolute_windows_forward_slashes() {
return array(
'drive root' => array( 'C:/' ),
'drive directory' => array( 'C:/WINDOWS' ),
'lowercase drive' => array( 'c:/foo/bar' ),
'nested directory' => array( 'D:/wamp/www/wp-content' ),
'wp_normalize_path() output' => array( wp_normalize_path( 'C:\\wamp\\www\\wp-content' ) ),
);
}

/**
* Tests that Windows drive-relative paths are not absolute.
*
* @ticket 48289
* @covers ::path_is_absolute
*/
public function test_path_is_absolute_rejects_windows_drive_relative_path() {
$this->assertFalse( path_is_absolute( 'C:foo' ) );
$this->assertFalse( path_is_absolute( 'C:' ) );
}

public function test_path_is_not_absolute() {
$relative_paths = array(
'',
Expand Down
Loading