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)
| 26 | |
| 27 | |
| 28 | def _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 | |
| 47 | def _within_tree(ceiling: Path, target: Path) -> bool: |
no outgoing calls
no test coverage detected