fix: normalize recursive listing paths to forward slashes (#6003)
This commit is contained in:
1 parent
43a404ca69
commit
2472fbcd30
3 files changed
+56
-4
No files matched your search
@@ -220,4 +220,52 @@ describe("checkConflict", () => {
|
|||||||
|
|
||||||
expect(conflicts).toHaveLength(0);
|
expect(conflicts).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Regression for #5980: a FileBrowser server running on Windows returns
|
||||||
|
// backslash-separated paths from the recursive listing. Without normalizing
|
||||||
|
// them, the prefix strip and key lookup never match, so the conflict modal is
|
||||||
|
// skipped and the backend returns a bare 409.
|
||||||
|
it("detects a conflict for backslash-separated server paths (Windows)", async () => {
|
||||||
|
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||||
|
{
|
||||||
|
path: "\\target\\file.txt",
|
||||||
|
name: "file.txt",
|
||||||
|
size: 10,
|
||||||
|
modified: "2026-06-04T00:00:00Z",
|
||||||
|
isDir: false,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const conflicts = await checkConflict(
|
||||||
|
[moveItem("file.txt", "/files/target/")],
|
||||||
|
"/files/target/"
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(conflicts).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("detects nested conflicts for backslash-separated server paths (Windows)", async () => {
|
||||||
|
vi.mocked(api.fetchAll).mockResolvedValue([
|
||||||
|
{
|
||||||
|
path: "\\target\\folder\\nested file.txt",
|
||||||
|
name: "nested file.txt",
|
||||||
|
size: 10,
|
||||||
|
modified: "2026-06-04T00:00:00Z",
|
||||||
|
isDir: false,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const files = [
|
||||||
|
{
|
||||||
|
name: "nested file.txt",
|
||||||
|
size: 12,
|
||||||
|
isDir: false,
|
||||||
|
fullPath: "folder/nested file.txt",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const conflicts = await checkConflict(files, "/files/target/");
|
||||||
|
|
||||||
|
expect(conflicts).toHaveLength(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -62,9 +62,10 @@ export async function checkConflict(
|
|||||||
const normBase = removePrefix(basePath).replace(/\/+$/, "");
|
const normBase = removePrefix(basePath).replace(/\/+$/, "");
|
||||||
const serverMap = new Map<string, RecursiveEntry>();
|
const serverMap = new Map<string, RecursiveEntry>();
|
||||||
for (const entry of serverEntries) {
|
for (const entry of serverEntries) {
|
||||||
const rel = entry.path.startsWith(normBase)
|
// A Windows server may return OS-native backslash separators; normalize to
|
||||||
? entry.path.slice(normBase.length)
|
// forward slashes so the prefix strip and key lookup line up.
|
||||||
: entry.path;
|
const path = entry.path.replace(/\\/g, "/");
|
||||||
|
const rel = path.startsWith(normBase) ? path.slice(normBase.length) : path;
|
||||||
serverMap.set(rel.replace(/^\/+/, ""), entry);
|
serverMap.set(rel.replace(/^\/+/, ""), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -424,7 +424,10 @@ var resourceGetRecursiveHandler = withUser(func(w http.ResponseWriter, r *http.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries = append(entries, RecursiveEntry{
|
entries = append(entries, RecursiveEntry{
|
||||||
Path: fPath,
|
// afero.Walk joins paths with the OS separator, so on Windows fPath
|
||||||
|
// uses backslashes. The web API contract is forward slashes, so
|
||||||
|
// normalize it here (mirrors search/search.go).
|
||||||
|
Path: filepath.ToSlash(fPath),
|
||||||
Name: info.Name(),
|
Name: info.Name(),
|
||||||
Size: info.Size(),
|
Size: info.Size(),
|
||||||
ModTime: info.ModTime(),
|
ModTime: info.ModTime(),
|
||||||
|
|||||||
Reference in new issue
Block a user