Skip to content

Commit 1d69ad6

Browse files
keithaignas
andauthored
fix: parsing metadata with inline licenses (#2806)
The wheel `METADATA` parsing implemented in 1.4 missed the fact that whitespace is significant and sometimes License is included inline in the `METADATA` file itself. This change ensures that we stop parsing the `METADATA` file only on first completely empty line. Fixes #2796 --------- Co-authored-by: Ignas Anikevicius <[email protected]>
1 parent e14cd37 commit 1d69ad6

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

python/private/pypi/whl_metadata.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def parse_whl_metadata(contents):
5252
"version": "",
5353
}
5454
for line in contents.strip().split("\n"):
55-
if not line.strip():
55+
if not line:
5656
# Stop parsing on first empty line, which marks the end of the
5757
# headers containing the metadata.
5858
break

tests/pypi/whl_metadata/whl_metadata_tests.bzl

+31
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,37 @@ Requires-Dist: this will be ignored
140140

141141
_tests.append(_test_parse_metadata_all)
142142

143+
def _test_parse_metadata_multiline_license(env):
144+
got = _parse_whl_metadata(
145+
env,
146+
# NOTE: The trailing whitespace here is meaningful as an empty line
147+
# denotes the end of the header.
148+
contents = """\
149+
Name: foo
150+
Version: 0.0.1
151+
License: some License
152+
153+
some line
154+
155+
another line
156+
157+
Requires-Dist: bar; extra == "all"
158+
Provides-Extra: all
159+
160+
Requires-Dist: this will be ignored
161+
""",
162+
)
163+
got.name().equals("foo")
164+
got.version().equals("0.0.1")
165+
got.requires_dist().contains_exactly([
166+
"bar; extra == \"all\"",
167+
])
168+
got.provides_extra().contains_exactly([
169+
"all",
170+
])
171+
172+
_tests.append(_test_parse_metadata_multiline_license)
173+
143174
def whl_metadata_test_suite(name): # buildifier: disable=function-docstring
144175
test_suite(
145176
name = name,

0 commit comments

Comments
 (0)