mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
Use portable POSIX parent paths instead of platform-dependent dirname() for remote navigation, previews, uploads, file operations and shared URLs. Normalize browser paths, avoid doubled root separators and preserve top-level directory names in ZIP downloads. Add regression coverage for root navigation, generated links, relative paths and ZIP members, and document the new test command. Verified with PHP syntax checks and all three regression suites.
32 lines
1.6 KiB
PHP
32 lines
1.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../Web/includes/remotepaths.php';
|
|
|
|
$parents = [
|
|
'/' => '/',
|
|
'/etc' => '/',
|
|
'/etc/' => '/',
|
|
'/etc/file.txt' => '/etc',
|
|
'//etc//file.txt' => '//etc',
|
|
'/folder with spaces/item.txt' => '/folder with spaces',
|
|
'folder/file.txt' => 'folder',
|
|
'file.txt' => '.',
|
|
'/a\\b/file.txt' => '/a\\b', // Backslash is a valid POSIX filename character.
|
|
];
|
|
foreach ($parents as $path => $expected) {
|
|
if (remoteDirname($path) !== $expected) throw new RuntimeException('Incorrect parent for ' . $path);
|
|
}
|
|
foreach (['/' => '/', '//etc/../' => '/', '/etc/../../' => '/', '/etc/./ssh/' => '/etc/ssh'] as $path => $expected) {
|
|
if (normalizePath($path) !== $expected) throw new RuntimeException('Incorrect normalized path for ' . $path);
|
|
}
|
|
// Round trips must remain correct on both Windows/XAMPP and Linux.
|
|
foreach (['/etc', '/mnt/raid', '/folder with spaces'] as $directory) {
|
|
$parent = normalizePath(remoteDirname($directory));
|
|
if ($parent !== ($directory === '/mnt/raid' ? '/mnt' : '/')) throw new RuntimeException('Invalid navigation round trip');
|
|
}
|
|
// ZIP paths keep the top-level directory name when it is directly under root.
|
|
foreach (['/etc' => '/etc/config.txt', '/mnt/raid' => '/mnt/raid/config.txt'] as $base => $file) {
|
|
$relative = substr($file, strlen(rtrim(remoteDirname($base), '/')) + 1);
|
|
if ($relative !== ($base === '/etc' ? 'etc/config.txt' : 'raid/config.txt')) throw new RuntimeException('Incorrect ZIP member path');
|
|
}
|
|
echo "Remote paths: POSIX parents, normalization, root navigation and ZIP paths passed.\n";
|