Skip to content

Commit 9ffdf1a

Browse files
committed
Simplify path processing
1 parent a46d274 commit 9ffdf1a

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

components/XML/Tests/W3CXMLConformanceTest.php

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -382,48 +382,20 @@ private static function collectTestCases( DOMNode $node, $base_path, array &$tes
382382

383383
private static function resolvePath( $base_path, $relative_path ) {
384384
if ( '' === $relative_path ) {
385-
return rtrim( $base_path, DIRECTORY_SEPARATOR );
385+
return $base_path;
386386
}
387387

388-
if ( preg_match( '#^(?:[a-zA-Z]+:)?/#', $relative_path ) ) {
389-
$resolved = realpath( $relative_path );
390-
391-
return false !== $resolved ? $resolved : self::normalizePath( $relative_path );
388+
// If it's an absolute path, use it directly
389+
if ( $relative_path[0] === '/' || preg_match( '#^[a-zA-Z]:#', $relative_path ) ) {
390+
return $relative_path;
392391
}
393392

393+
// Otherwise concatenate and let realpath() normalize it
394394
$candidate = rtrim( $base_path, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $relative_path;
395395
$resolved = realpath( $candidate );
396396

397-
return false !== $resolved ? $resolved : self::normalizePath( $candidate );
398-
}
399-
400-
private static function normalizePath( $path ) {
401-
$path = str_replace( '\\', '/', $path );
402-
403-
$segments = explode( '/', $path );
404-
$resolved = array();
405-
406-
$prefix = '';
407-
if ( isset( $segments[0] ) && preg_match( '#^[a-zA-Z]:$#', $segments[0] ) ) {
408-
$prefix = array_shift( $segments ) . '/';
409-
} elseif ( isset( $segments[0] ) && '' === $segments[0] ) {
410-
$prefix = '/';
411-
array_shift( $segments );
412-
}
413-
414-
foreach ( $segments as $segment ) {
415-
if ( '' === $segment || '.' === $segment ) {
416-
continue;
417-
}
418-
419-
if ( '..' === $segment ) {
420-
array_pop( $resolved );
421-
continue;
422-
}
423-
424-
$resolved[] = $segment;
425-
}
426-
427-
return $prefix . implode( '/', $resolved );
397+
// If realpath fails (file doesn't exist), return the candidate anyway
398+
// We check is_file() later, so non-existent paths will be skipped
399+
return false !== $resolved ? $resolved : $candidate;
428400
}
429401
}

0 commit comments

Comments
 (0)