WordPress.org

Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#46561 new enhancement

Make wp_normalize_path() on Windows resolve drive letter for drive–relative paths

Reported by: Rarst Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Filesystem API Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

Though rarely used, Windows allows to omit drive letter in file path to treat is as drive–relative.

This causes inconsistency where paths pointing to the same dir are not normalized to the same representation by wp_normalize_path():

<?php
var_dump( wp_normalize_path( 'C:\server\www\dev' ) );
// "C:/server/www/dev

var_dump( wp_normalize_path( '\server\www\dev' ) );
// /server/www/dev << same path, but mismatch after normalize

var_dump( wp_normalize_path( realpath( '\server\www\dev' ) ) );
// C:/server/www/dev << resolved drive letter before normalize

I think drive letter should be explicitly resolved as part of normalization for this case.

Change History (3)

#1 @Rarst
9 months ago

  • Summary changed from Make wp_nomralize_path() on Windows resolve drive letter for drive–relative paths to Make wp_normalize_path() on Windows resolve drive letter for drive–relative paths

#2 @Rarst
9 months ago

One problem is that wp_normalize_path() doesn’t require path to be real, it normalizes path strings really. Introducing file_exists() check here feels somewhat unwanted.

Maybe we should introduce a new function, something like wp_normalize_real_path() that will both validate path as valid filesystem path and normalize it?

#3 @SergeyBiryukov
9 months ago

  • Component changed from General to Filesystem API
Note: See TracTickets for help on using tickets.