INNER CODE UNIT · Python

is_under

Dsadd4/AgentFigureGallery · agentfiguregallery/server.py:50

def is_under(path: Path, parent: Path) -> bool:
    try:
        path.resolve().relative_to(parent.resolve())
        return True
    except ValueError:
        return False


def safe_path(root: Path, raw: str) -> Path:
    path = Path(unquote(raw)).expanduser()
    if not path.is_absolute():
        path = root / path
    path = path.resolve()
    if not is_under(path, root):
        raise ValueError(f"Path is outside AgentFigureGallery root: {path}")
    return path

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…