Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unpacking wheels that contain files with commas in their names #427

Merged
merged 16 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/wheel/wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
from collections import OrderedDict
from distutils import log as logger
from io import TextIOWrapper
from zipfile import ZIP_DEFLATED, ZipInfo, ZipFile

from wheel.cli import WheelError
Expand Down Expand Up @@ -60,23 +61,24 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED):
raise WheelError('Missing {} file'.format(self.record_path))

with record:
for line in record:
line = line.decode('utf-8')
path, hash_sum, size = line.rsplit(u',', 2)
if hash_sum:
algorithm, hash_sum = hash_sum.split(u'=')
try:
hashlib.new(algorithm)
except ValueError:
raise WheelError('Unsupported hash algorithm: {}'.format(algorithm))

if algorithm.lower() in {'md5', 'sha1'}:
raise WheelError(
'Weak hash algorithm ({}) is not permitted by PEP 427'
.format(algorithm))

self._file_hashes[path] = (
algorithm, urlsafe_b64decode(hash_sum.encode('ascii')))
for line in csv.reader(TextIOWrapper(record, newline=u'')):
path, hash_sum, size = line
if not hash_sum:
continue

algorithm, hash_sum = hash_sum.split(u'=')
try:
hashlib.new(algorithm)
except ValueError:
raise WheelError('Unsupported hash algorithm: {}'.format(algorithm))

if algorithm.lower() in {'md5', 'sha1'}:
raise WheelError(
'Weak hash algorithm ({}) is not permitted by PEP 427'
.format(algorithm))

self._file_hashes[path] = (
algorithm, urlsafe_b64decode(hash_sum.encode('ascii')))

def open(self, name_or_info, mode="r", pwd=None):
def _update_crc(newdata, eof=None):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@pytest.fixture(scope='session')
def wheels_and_eggs(tmpdir_factory):
"""Build wheels and eggs from test distributions."""
test_distributions = "complex-dist", "simple.dist", "headers.dist"
test_distributions = "complex-dist", "simple.dist", "headers.dist", "commasinfilenames.dist"
if sys.version_info >= (3, 6):
# Only Python 3.6+ can handle packaging unicode file names reliably
# across different platforms
Expand Down
Empty file.
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions tests/testdata/commasinfilenames.dist/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup

setup(
name='testrepo',
version='0.1',
packages=["mypackage"],
description='A test package with commas in file names',
include_package_data=True,
package_data={
"mypackage.data": ["*"]
},
)