is_safe_path#

scikitplot.cython.is_safe_path(path, *, allow_absolute=False)[source]#

Return True when a filesystem path does not contain traversal sequences.

Parameters:
pathstr or os.PathLike

Path to validate.

allow_absolutebool, default=False

If False, absolute paths are considered unsafe.

Returns:
bool

True if the path passes all checks, False otherwise.

Parameters:
Return type:

bool

Notes

Path-traversal sequences (../, ..\\, ~) are always rejected regardless of allow_absolute.

Examples

>>> is_safe_path("include/mylib")
True
>>> is_safe_path("../../../etc/passwd")
False
>>> is_safe_path("/usr/include", allow_absolute=True)
True
>>> is_safe_path("/usr/include", allow_absolute=False)
False