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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/wheel/wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os.path
import re
import stat
import sys
import time
from collections import OrderedDict
from distutils import log as logger
Expand All @@ -13,6 +14,16 @@
from wheel.cli import WheelError
from wheel.util import urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO

if sys.version_info >= (3,):
from io import TextIOWrapper

def read_csv(fp):
return csv.reader(TextIOWrapper(fp, newline='', encoding='utf-8'))
else:
def read_csv(fp):
for line in csv.reader(fp):
yield [column.decode('utf-8') for column in line]

# Non-greedy matching of an optional build number may be too clever (more
# invalid wheel filenames will match). Separate regex for .dist-info?
WHEEL_INFO_RE = re.compile(
Expand Down Expand Up @@ -60,23 +71,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 read_csv(record):
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": ["*"]
},
)