#33265 closed enhancement (fixed)
Normalize drive letter in paths
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.3 |
Component: | Filesystem API | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Windows platform mostly treats paths as case-insensitive. However WordPress tends to use case-sensitive comparisons for paths.
Introduction of wp_normalize_path()
gave an API way to deal with slashes consistently.
Another issue it could handle is consistent case of drive letter.
Due to varied possible sources of paths (PHP, web server, user configuration) mismatch in case of drive letter is relatively common (anecdotally I have encountered it multiple times in different contexts), ruins case-sensitive paths comparisons, and is hard to notice and debug.
I would suggest to uppercase drive letter in wp_normalize_path()
.
Upper case would be consistent with PHP constants (such as __FILE__
) and historical Windows conventions (as far as I am aware there is no formal rule which is "correct" case).
Attachments (3)
Change History (13)
This ticket was mentioned in Slack in #core by sergey. View the logs.
10 years ago
#3
@
10 years ago
- Component changed from General to Filesystem API
- Keywords has-patch commit added
- Owner set to dd32
- Status changed from new to assigned
33265.diff looks good to me.
#5
@
10 years ago
Looks like this is a great moment to add general tests for wp_normalize_path()
in addition to a test for the uppercase drive letters. Patch with tests coming up.
@
10 years ago
Adding tests for wp_normalize_path()
: general and uppercase drive letter cases included.
#6
@
10 years ago
- Keywords 2nd-opinion needs-unit-tests removed
And by the way, I suggest using ucfirst()
for capitalizing the drive letter. It seems to be a more efficient and short way to do that IMHO. Patch coming up for that as well.
@
10 years ago
Improved @dd32's patch by making the drive letter capitalization shorter and more efficient.
#9
@
10 years ago
Could be even quicker if you don't bother to check for the colon.
just do ucfirst()
Assumption is that on nix systems the first letter is a '/' which doesn't get changed.
Are there cases where the $path does validly start with a letter that's not a drive letter
and should therefore not be uppercased.
I'm of two minds here
Due to the PHP constants always returning uppercase drive letters, I'm inclined to go that way through.
33265.diff implements that, still not 100% sure which way though.