Return a sanitised relative path for which os.path.abspath(os.path.join(base, path)).startswith(base)
(self, path)
| 411 | return os.path.join(self._destpath, netloc, upath) |
| 412 | |
| 413 | def _sanitize_relative_path(self, path): |
| 414 | """Return a sanitised relative path for which |
| 415 | os.path.abspath(os.path.join(base, path)).startswith(base) |
| 416 | """ |
| 417 | last = None |
| 418 | path = os.path.normpath(path) |
| 419 | while path != last: |
| 420 | last = path |
| 421 | # Note: os.path.join treats '/' as os.sep on Windows |
| 422 | path = path.lstrip(os.sep).lstrip('/') |
| 423 | path = path.lstrip(os.pardir).removeprefix('..') |
| 424 | drive, path = os.path.splitdrive(path) # for Windows |
| 425 | return path |
| 426 | |
| 427 | def exists(self, path): |
| 428 | """ |