mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-01 20:03:30 +02:00
feat(filesystem): improve path normalization in SurfSenseFilesystemMiddleware to handle Windows-style paths and mixed separators
This commit is contained in:
parent
30b55a9baa
commit
7063d6d1e4
4 changed files with 117 additions and 6 deletions
|
|
@ -787,17 +787,20 @@ class SurfSenseFilesystemMiddleware(FilesystemMiddleware):
|
|||
) -> str:
|
||||
backend = self._get_backend(runtime)
|
||||
mount_prefix = self._default_mount_prefix(runtime)
|
||||
normalized_candidate = re.sub(r"/+", "/", candidate.strip().replace("\\", "/"))
|
||||
if not mount_prefix or not isinstance(backend, MultiRootLocalFolderBackend):
|
||||
return candidate if candidate.startswith("/") else f"/{candidate.lstrip('/')}"
|
||||
if normalized_candidate.startswith("/"):
|
||||
return normalized_candidate
|
||||
return f"/{normalized_candidate.lstrip('/')}"
|
||||
|
||||
mount_names = set(backend.list_mounts())
|
||||
if candidate.startswith("/"):
|
||||
first_segment = candidate.lstrip("/").split("/", 1)[0]
|
||||
if normalized_candidate.startswith("/"):
|
||||
first_segment = normalized_candidate.lstrip("/").split("/", 1)[0]
|
||||
if first_segment in mount_names:
|
||||
return candidate
|
||||
return f"{mount_prefix}{candidate}"
|
||||
return normalized_candidate
|
||||
return f"{mount_prefix}{normalized_candidate}"
|
||||
|
||||
relative = candidate.lstrip("/")
|
||||
relative = normalized_candidate.lstrip("/")
|
||||
first_segment = relative.split("/", 1)[0]
|
||||
if first_segment in mount_names:
|
||||
return f"/{relative}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue