[wp-trac] [WordPress Trac] #46561: Make wp_normalize_path() on Windows resolve drive letter for drive–relative paths
WordPress Trac
noreply at wordpress.org
Sun Mar 12 02:29:56 UTC 2023
#46561: Make wp_normalize_path() on Windows resolve drive letter for drive–relative
paths
--------------------------------------+------------------------------
Reporter: Rarst | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Filesystem API | Version: 3.9
Severity: minor | Resolution:
Keywords: needs-patch dev-feedback | Focuses:
--------------------------------------+------------------------------
Changes (by costdev):
* keywords: needs-patch => needs-patch dev-feedback
* version: => 3.9
Comment:
Rather than introduce a new function, or use `file_exists()` for all set
ups, what about only running `realpath()` when the OS is windows, and the
path begins with `'/'`?
Something like this:
{{{#!php
<?php
// function wp_normalize_path...
// ...
/*
* On Windows, if the path starts with '/' after normalizing,
* try detecting the real path to apply the correct drive letter.
*/
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) && str_starts_with(
$path, '/' ) ) {
$realpath = realpath( $path );
if ( is_string( $realpath ) ) {
$path = $realpath;
}
}
return $wrapper . $path;
}}}
This would mean having the correct result for existing paths, and local
testing seems to show this working properly:
{{{#!php
<?php
var_dump( wp_normalize_path( '\Users\costdev\test_normalize.php' ) );
// C:\Users\costdev\test_normalize.php
}}}
-----
- As this would be new functionality, setting `Version` to `3.9` when
`wp_normalize_path()` was introduced.
- Adding `dev-feedback` to gather thoughts.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46561#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list