ducklm/duck_core/tools/paths.py

14 lines
372 B
Python

from pathlib import Path
class WorkspacePathError(ValueError):
pass
def resolve_workspace_path(workspace: str, relative_path: str) -> Path:
root = Path(workspace).resolve()
path = (root / relative_path).resolve()
if root != path and root not in path.parents:
raise WorkspacePathError(f"Path escapes workspace: {relative_path}")
return path