MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _bash_source_suffix

Function _bash_source_suffix

graphify/extractors/bash.py:28–44  ·  view source on GitHub ↗

Return the literal path suffix of a variable-built `source` argument, or None when the remainder is empty or still holds an expansion. ``"${DIR}/lib/x.sh"`` -> ``"lib/x.sh"``. When *allow_dotdot* is False (the default — the base is a script-dir guess), ``..`` segments are rejected

(raw: str, allow_dotdot: bool = False)

Source from the content-addressed store, hash-verified

26
27
28def _bash_source_suffix(raw: str, allow_dotdot: bool = False) -> str | None:
29 """Return the literal path suffix of a variable-built `source` argument, or
30 None when the remainder is empty or still holds an expansion.
31
32 ``"${DIR}/lib/x.sh"`` -> ``"lib/x.sh"``.
33
34 When *allow_dotdot* is False (the default — the base is a script-dir guess),
35 ``..`` segments are rejected to prevent traversal outside the project tree.
36 When True (the base is a tracked var_bases entry — a known directory),
37 ``..`` is permitted and the caller normalises with ``os.path.normpath``.
38 """
39 suffix = _BASH_LEADING_EXPANSION.sub("", raw, count=1).lstrip("/")
40 if not suffix or "$" in suffix:
41 return None
42 if not allow_dotdot and ".." in suffix.split("/"):
43 return None
44 return suffix
45
46
47def _within_tree(ceiling: Path, target: Path) -> bool:

Callers 2

invoked_scriptFunction · 0.85
_process_source_commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected