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

Make sure filenames containing commas are quoted when writing RECORD file for wheel #61

Merged
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
19 changes: 16 additions & 3 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import contextlib
import csv
import hashlib
import logging
import os
Expand All @@ -12,11 +13,13 @@
import zipfile

from base64 import urlsafe_b64encode
from io import BytesIO
from io import StringIO

from packaging.tags import sys_tags
from poetry.core import __version__
from poetry.core.semver import parse_constraint
from poetry.core.utils._compat import PY2
from poetry.core.utils._compat import decode

from ..utils.helpers import escape_name
Expand All @@ -37,7 +40,6 @@


class WheelBuilder(Builder):

format = "wheel"

def __init__(self, poetry, target_dir=None, original=None):
Expand Down Expand Up @@ -179,10 +181,21 @@ def _write_metadata(self, wheel):
def _write_record(self, wheel):
# Write a record of the files in the wheel
with self._write_to_zip(wheel, self.dist_info + "/RECORD") as f:
record = StringIO() if not PY2 else BytesIO()

csv_writer = csv.writer(
record,
delimiter=csv.excel.delimiter,
quotechar=csv.excel.quotechar,
lineterminator="\n",
)
for path, hash, size in self._records:
f.write("{},sha256={},{}\n".format(path, hash, size))
csv_writer.writerow((path, "sha256={}".format(hash), size))

# RECORD itself is recorded with no hash or size
f.write(self.dist_info + "/RECORD,,\n")
csv_writer.writerow((self.dist_info + "/RECORD", "", ""))

f.write(decode(record.getvalue()))

@property
def dist_info(self): # type: () -> str
Expand Down
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions tests/masonry/builders/fixtures/comma_file/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tool.poetry]
name = "comma-file"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]

13 changes: 13 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,16 @@ def test_wheel_package_pep_561_stub_only_includes_typed_marker():

with zipfile.ZipFile(str(whl)) as z:
assert "pkg-stubs/py.typed" in z.namelist()


def test_wheel_with_file_with_comma():
root = fixtures_dir / "comma_file"
WheelBuilder.make(Factory().create_poetry(root))

whl = root / "dist" / "comma_file-1.2.3-py3-none-any.whl"

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
records = z.read("comma_file-1.2.3.dist-info/RECORD")
assert '\n"comma_file/a,b.py"' in records.decode()