MCPcopy Index your code
hub / github.com/python/cpython / _sanitize_filename

Function _sanitize_filename

Lib/zipfile/__init__.py:404–420  ·  view source on GitHub ↗

Terminate the file name at the first null byte and ensure paths always use forward slashes as the directory separator.

(filename)

Source from the content-addressed store, hash-verified

402 return None
403
404def _sanitize_filename(filename):
405 """Terminate the file name at the first null byte and
406 ensure paths always use forward slashes as the directory separator."""
407
408 # Terminate the file name at the first null byte. Null bytes in file
409 # names are used as tricks by viruses in archives.
410 null_byte = filename.find(chr(0))
411 if null_byte >= 0:
412 filename = filename[0:null_byte]
413 # This is used to ensure paths in generated ZIP files always use
414 # forward slashes as the directory separator, as required by the
415 # ZIP format specification.
416 if os.sep != "/" and os.sep in filename:
417 filename = filename.replace(os.sep, "/")
418 if os.altsep and os.altsep != "/" and os.altsep in filename:
419 filename = filename.replace(os.altsep, "/")
420 return filename
421
422
423class ZipInfo:

Callers 2

__init__Method · 0.85
_decodeExtraMethod · 0.85

Calls 2

findMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…