mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
Fix SFTP root navigation on Windows
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.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?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";
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../Web/includes/workspace.php';
|
||||
require_once __DIR__ . '/../Web/includes/remotepaths.php';
|
||||
require_once __DIR__ . '/../Web/content/ftp/lib/serverstats.php';
|
||||
set_error_handler(function ($severity, $message, $file, $line) {
|
||||
if (error_reporting() & $severity) throw new ErrorException($message, 0, $severity, $file, $line);
|
||||
@@ -8,9 +9,8 @@ function expectWorkspace($condition, $message) {
|
||||
if (!$condition) throw new RuntimeException($message);
|
||||
}
|
||||
|
||||
function renderWorkspaceFixture($name, $admin = true) {
|
||||
function renderWorkspaceFixture($name, $admin = true, $defaultPath = '/mnt/raid', $currentPath = '/mnt/raid/Workspace') {
|
||||
$_SESSION = ['uname' => 'michal', 'admin' => $admin, 'upPer' => true, 'downPer' => true, 'delPer' => true];
|
||||
$defaultPath = '/mnt/raid'; $currentPath = '/mnt/raid/Workspace';
|
||||
$filePath = $currentPath . '/Example.pdf'; $fileName = basename($filePath); $parentDir = $currentPath;
|
||||
$fileExtension = 'png'; $fileSize = 245760; $mimeType = 'image/png';
|
||||
$isImage = true; $isVideo = false; $isAudio = false;
|
||||
@@ -75,6 +75,12 @@ foreach ($pages as $name) {
|
||||
$member = renderWorkspaceFixture('index', false);
|
||||
expectWorkspace(strpos($member, 'User management') === false && strpos($member, '> Server status</a>') === false, 'Member navigation omits admin pages');
|
||||
expectWorkspace(strpos($member, 'Account settings') !== false, 'Members can access account settings');
|
||||
$rootChild = renderWorkspaceFixture('index', true, '/', '/etc');
|
||||
expectWorkspace(strpos($rootChild, 'href="?path=%2F"') !== false, 'Parent link from a root child uses a POSIX slash');
|
||||
expectWorkspace(strpos($rootChild, '%5C') === false, 'No Windows separator in remote links');
|
||||
$root = renderWorkspaceFixture('index', true, '/', '/');
|
||||
expectWorkspace(strpos($root, 'Parent folder') === false, 'Root has no parent-folder link');
|
||||
expectWorkspace(strpos($root, 'href="?path=%2FDocuments"') !== false, 'Root children use a single leading slash');
|
||||
if ($preview) {
|
||||
// One-page PDF fixture for viewer navigation and fullscreen checks.
|
||||
$stream = "BT /F1 24 Tf 60 700 Td (USB RAID workspace preview) Tj ET";
|
||||
|
||||
Reference in New Issue
Block a user