From db1e69ad49af16104a40f6fd6bed84006726956e Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Mon, 23 Nov 2026 12:07:20 -0500 Subject: [PATCH] Filesystem API: Recognize Windows drive-letter paths with forward slashes as absolute --- src/wp-includes/functions.php | 7 +++--- tests/phpunit/tests/functions.php | 39 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 59d91815d122e..9a84527111e61 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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. @@ -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; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 51419799dbd16..1e7985b433547 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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( '',