This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: About Zipfile
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Fcscanf, eric.smith, ronaldoussoren
Priority: normal Keywords:

Created on 2021-02-26 03:27 by Fcscanf, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Fcant_2021-02-26_11-26-37.jpg Fcscanf, 2021-02-26 03:27
Messages (4)
msg387705 - (view) Author: Fcant (Fcscanf) Date: 2021-02-26 03:27
When I Unzip a package using the zipfile module, the package’s filename has a newline character, which causes the Unzip to fail, so the UNZIP filename needs to be processed
msg387714 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2021-02-26 09:15
I'm not sure what you are asking here.

Looking at the screenshot I'd say that the zipfile you are trying to extract contains files with a newline in their name. That's a perfectly valid (although annoying) name on unix-y platforms. 

The zipfile module does not have an API for rewriting the file name when extracting. It is far from clear to me that adding such a API would be generally useful. 

Emulating this is fairly easy though, something like:

zf = zipfile.ZipFile(...)
for name in zf.namelist():
    stream = zf.open(name)
    data = stream.read()
    stream.close()
    with open(name.replace(...), "w") as stream:
        stream.write(data)
msg387715 - (view) Author: Fcant (Fcscanf) Date: 2021-02-26 09:21
Because these special symbols are not handled under the Window, he will report an error and will not work properly

From:樊乘乘
Email:fcscanf@outlook.com<mailto:fcscanf@outlook.com>
Tel:17826260016

发件人: Ronald Oussoren<mailto:report@bugs.python.org>
发送时间: 2021年2月26日 樊乘 17:15
收件人: fcscanf@outlook.com<mailto:fcscanf@outlook.com>
主题: [issue43326] About Zipfile

Ronald Oussoren <ronaldoussoren@mac.com> added the comment:

I'm not sure what you are asking here.

Looking at the screenshot I'd say that the zipfile you are trying to extract contains files with a newline in their name. That's a perfectly valid (although annoying) name on unix-y platforms.

The zipfile module does not have an API for rewriting the file name when extracting. It is far from clear to me that adding such a API would be generally useful.

Emulating this is fairly easy though, something like:

zf = zipfile.ZipFile(...)
for name in zf.namelist():
    stream = zf.open(name)
    data = stream.read()
    stream.close()
    with open(name.replace(...), "w") as stream:
        stream.write(data)

----------
nosy: +ronaldoussoren

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue43326>
_______________________________________
msg387720 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-02-26 11:25
I don't think there's a problem with Python here.

The complaint seems to be one or more of:
- The creating software allowed a newline to be in the filename.
- Windows allows the creation of filenames with newlines.
- The Windows UI doesn't handle filenames with newlines well.

In any event, Python can't do anything about these problems. I suggest we close this issue.
History
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87492
2021-02-27 09:01:53eric.smithsetresolution: not a bug
2021-02-27 04:33:19Fcscanfsetstatus: open -> closed
stage: resolved
2021-02-26 11:25:49eric.smithsetnosy: + eric.smith
messages: + msg387720
2021-02-26 09:21:11Fcscanfsetmessages: + msg387715
2021-02-26 09:15:47ronaldoussorensetnosy: + ronaldoussoren
messages: + msg387714
2021-02-26 03:27:00Fcscanfcreate