Resolve *rel* against *root* and verify it stays within *root*. Raises ``ValueError`` if *rel* is absolute, contains ``..`` segments that escape *root*, or otherwise resolves outside the project root.
(rel: Path, root: Path)
| 27 | |
| 28 | |
| 29 | def _validate_rel_path(rel: Path, root: Path) -> Path: |
| 30 | """Resolve *rel* against *root* and verify it stays within *root*. |
| 31 | |
| 32 | Raises ``ValueError`` if *rel* is absolute, contains ``..`` segments |
| 33 | that escape *root*, or otherwise resolves outside the project root. |
| 34 | """ |
| 35 | if rel.is_absolute(): |
| 36 | raise ValueError( |
| 37 | f"Absolute paths are not allowed in manifests: {rel}" |
| 38 | ) |
| 39 | resolved = (root / rel).resolve() |
| 40 | root_resolved = root.resolve() |
| 41 | try: |
| 42 | resolved.relative_to(root_resolved) |
| 43 | except ValueError: |
| 44 | raise ValueError( |
| 45 | f"Path {rel} resolves to {resolved} which is outside " |
| 46 | f"the project root {root_resolved}" |
| 47 | ) from None |
| 48 | return resolved |
| 49 | |
| 50 | |
| 51 | def _manifest_path_label(root: Path, path: Path) -> str: |
no test coverage detected