is_safe_path#
- scikitplot.cython.is_safe_path(path, *, allow_absolute=False)[source]#
Return
Truewhen 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
Trueif the path passes all checks,Falseotherwise.
- Parameters:
- Return type:
Notes
Path-traversal sequences (
../,..\\,~) are always rejected regardless ofallow_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