summaryrefslogtreecommitdiff
path: root/plugins/claude-security/scripts/lib/absolute.py
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-09-09 22:10:55 +0000
committerClaude <noreply@anthropic.com>2026-09-09 22:10:55 +0000
commit9771d67eb06a525d9235c00108b2392ca1b92d7c (patch)
treefb9f2cfad9395d1e4ffd0e8f6c6e10cb2b3d6110 /plugins/claude-security/scripts/lib/absolute.py
parent0c81ec93038e0bff9e9af08266d61102a667d19e (diff)
parent3ea32df27be71d78775e627df2382fc26203577f (diff)
Merge branch 'main' into tobin/add-hubspot-salestobin/add-hubspot-sales
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()