Terminate the file name at the first null byte and ensure paths always use forward slashes as the directory separator.
(filename)
| 402 | return None |
| 403 | |
| 404 | def _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 | |
| 423 | class ZipInfo: |
no test coverage detected
searching dependent graphs…