Skip to content

Excess spaces at the end of files or repositorys are not handle when extracting zip files on Windows. #94018

Closed
@Rygone

Description

@Rygone

Bug report

Excess spaces at the end of files or repositorys are not handle when extracting zip files on Windows.
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Documents \\test.txt'

Can be tested with this Documents.zip
and this piece of code:

from zipfile import ZipFile
with ZipFile('Documents.zip', 'r') as zip:
    zip.extractall()

Fix proposal

cpython/Lib/zipfile.py : 1690

# remove end spaces
def remove_end_spaces(x):
    for c in x[::-1]:
        if(c == ' '): x = x[:-1]
        else: return x
arcname = (remove_end_spaces(x) for x in arcname)

Your environment

  • CPython versions tested on: python 3.9
  • Operating system and architecture: Windows 10 Professionnel 21H2 19044.1706

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions