Refactor path handling in PageNode class for improved reliability
Some checks failed
Docker Build Test / build (3.11) (pull_request) Successful in 1m9s
Docker Build Test / build (3.10) (pull_request) Successful in 1m12s
Docker Build Test / build (3.12) (pull_request) Successful in 1m8s
Docker Build Test / build (3.13) (pull_request) Failing after 2s
Build and Publish Docker Image / build (pull_request) Failing after 2s
Run Tests / test (windows-latest, 3.10) (pull_request) Has been cancelled
Run Tests / test (windows-latest, 3.11) (pull_request) Has been cancelled
Run Tests / test (windows-latest, 3.12) (pull_request) Has been cancelled
Run Tests / test (windows-latest, 3.13) (pull_request) Has been cancelled
Run Tests / test (windows-latest, 3.9) (pull_request) Has been cancelled
Docker Build Test / build (3.9) (pull_request) Failing after 2s
Run Tests / test (ubuntu-latest, 3.10) (pull_request) Failing after 2s
Run Tests / test (ubuntu-latest, 3.11) (pull_request) Failing after 2s
Run Tests / test (ubuntu-latest, 3.12) (pull_request) Failing after 1s
Run Tests / test (ubuntu-latest, 3.13) (pull_request) Failing after 1s
Run Tests / test (ubuntu-latest, 3.9) (pull_request) Failing after 2s

- Updated path resolution for pages and files to use `resolve()` method, ensuring absolute paths are handled correctly.
- Enhanced relative path calculation using `relative_to()` to improve robustness against invalid paths.
- Adjusted request path formatting to include a leading slash for consistency.
This commit is contained in:
2025-12-02 11:03:58 -06:00
parent 4ec44900cf
commit ccf954681b

View File

@@ -129,7 +129,7 @@ class PageNode:
with self._lock:
self.servedpages = pages
pagespath = Path(self.pagespath)
pagespath = Path(self.pagespath).resolve()
if not (pagespath / "index.mu").is_file():
self.destination.register_request_handler(
@@ -139,10 +139,12 @@ class PageNode:
)
for full_path in pages:
rel = full_path[len(str(pagespath)) :]
if not rel.startswith("/"):
rel = "/" + rel
request_path = f"/page{rel}"
page_path = Path(full_path).resolve()
try:
rel = page_path.relative_to(pagespath).as_posix()
except ValueError:
continue
request_path = f"/page/{rel}"
self.destination.register_request_handler(
request_path,
response_generator=self.serve_page,
@@ -156,13 +158,15 @@ class PageNode:
with self._lock:
self.servedfiles = files
filespath = Path(self.filespath)
filespath = Path(self.filespath).resolve()
for full_path in files:
rel = full_path[len(str(filespath)) :]
if not rel.startswith("/"):
rel = "/" + rel
request_path = f"/file{rel}"
file_path = Path(full_path).resolve()
try:
rel = file_path.relative_to(filespath).as_posix()
except ValueError:
continue
request_path = f"/file/{rel}"
self.destination.register_request_handler(
request_path,
response_generator=self.serve_file,