summaryrefslogtreecommitdiff
path: root/plugins/claude-security/scripts/lib/absolute.py
diff options
context:
space:
mode:
authorTobin South <tobin.south@gmail.com>2026-09-01 11:36:49 -0700
committerGitHub <noreply@github.com>2026-09-01 11:36:49 -0700
commite18ff5086423bd9c21902ce3100dc4ecc84a668a (patch)
tree7ed935773a561a74448b1fa42d6bcb135be7fb11 /plugins/claude-security/scripts/lib/absolute.py
parent4b909c3492b350cdc42160ffe4b135e6f5c1db12 (diff)
parentf85f7cfcbbe9c949ba63304add8be7daf5c13e78 (diff)
Merge pull request #5728 from anthropics/claude-security-v0.11.0
Diffstat (limited to 'plugins/claude-security/scripts/lib/absolute.py')
-rw-r--r--plugins/claude-security/scripts/lib/absolute.py13
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()