diff options
| author | mmoore <mmoore@anthropic.com> | 2026-09-01 11:18:30 -0700 |
|---|---|---|
| committer | mmoore <mmoore@anthropic.com> | 2026-09-01 11:18:30 -0700 |
| commit | f85f7cfcbbe9c949ba63304add8be7daf5c13e78 (patch) | |
| tree | 7ed935773a561a74448b1fa42d6bcb135be7fb11 /plugins/claude-security/scripts/lib/absolute.py | |
| parent | 4b909c3492b350cdc42160ffe4b135e6f5c1db12 (diff) | |
Claude Security Plugin - v0.11.0claude-security-v0.11.0
Diffstat (limited to 'plugins/claude-security/scripts/lib/absolute.py')
| -rw-r--r-- | plugins/claude-security/scripts/lib/absolute.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/plugins/claude-security/scripts/lib/absolute.py b/plugins/claude-security/scripts/lib/absolute.py index 45f28ed3..fa72a510 100644 --- a/plugins/claude-security/scripts/lib/absolute.py +++ b/plugins/claude-security/scripts/lib/absolute.py @@ -1,9 +1,10 @@ -"""Whether a path is spelled absolutely on any platform, not just the one this runs on.""" +"""Whether a path is absolute on any platform, and where an absolute path sits under a root.""" from __future__ import annotations import ntpath import os +from pathlib import PurePath def spelled(path: str) -> bool: @@ -13,3 +14,13 @@ def spelled(path: str) -> bool: or path.replace("\\", "/").startswith("/") or bool(ntpath.splitdrive(path)[0]) ) + + +def relative(path: str, root: str) -> str | None: + """Where a normalised absolute `path` sits below `root`, as "a/b" ("." for root); else None.""" + try: + inside = PurePath(path).relative_to(root) + except ValueError: + return None + # A ".." could name somewhere above root; a normalised path never carries one. + return None if ".." in inside.parts else inside.as_posix() |
