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 <240938+aignas@users.noreply.github.com>
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 31 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy