MCPcopy Index your code
hub / github.com/github/spec-kit / _validate_rel_path

Function _validate_rel_path

src/specify_cli/integrations/manifest.py:29–48  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

27
28
29def _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
51def _manifest_path_label(root: Path, path: Path) -> str:

Callers 5

install_shared_infraFunction · 0.85
record_fileMethod · 0.85
record_existingMethod · 0.85
removeMethod · 0.85
is_recoveredMethod · 0.85

Calls 1

resolveMethod · 0.45

Tested by

no test coverage detected