diff options
author | Fred Drake <fdrake@acm.org> | 2001-07-19 19:44:25 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-07-19 19:44:25 (GMT) |
commit | a58947f60098b07471ad6771b185557081d14a4c (patch) | |
tree | 6851eb3c9437d6cbb8c1de12dc6588d947afed73 /Lib | |
parent | d4f7f609bfd1ff57f59705b2383305478fb7c411 (diff) | |
download | cpython-a58947f60098b07471ad6771b185557081d14a4c.zip cpython-a58947f60098b07471ad6771b185557081d14a4c.tar.gz cpython-a58947f60098b07471ad6771b185557081d14a4c.tar.bz2 |
Make sure path names inserted into ZIP files are normalized to use "/" as
the directory separator, as required by the format specification.
This closes SF bug #440693.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/zipfile.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 8a113a0..bd9df9b 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -89,7 +89,7 @@ class ZipInfo: """Class with attributes describing each file in the ZIP archive.""" def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)): - self.filename = filename # Name of the file in the archive + self.filename = _normpath(filename) # Name of the file in the archive self.date_time = date_time # year, month, day, hour, min, sec # Standard values: self.compress_type = ZIP_STORED # Type of compression for the file @@ -130,6 +130,17 @@ class ZipInfo: return header + self.filename + self.extra +# This is used to ensure paths in generated ZIP files always use +# forward slashes as the directory separator, as required by the +# ZIP format specification. +if os.sep != "/": + def _normpath(path): + return path.replace(os.sep, "/") +else: + def _normpath(path): + return path + + class ZipFile: """ Class with methods to open, read, write, close, list zip files. |