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