Skip to content

Commit 33d7ed7

Browse files
committed
test: cover malformed wheel anchor in parse_simpleapi_html
Add a regression test for the previous fix: an anchor whose filename does not parse as a valid PEP 427 wheel name (fewer than 4 `-` separators, e.g. `six.whl`) is skipped, and a valid wheel in the same response is still returned.
1 parent 00856d5 commit 33d7ed7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/pypi/parse_simpleapi_html/parse_simpleapi_html_tests.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,33 @@ def _test_whls(env):
304304

305305
_tests.append(_test_whls)
306306

307+
def _test_malformed_whl_anchor_is_skipped(env):
308+
# Some index servers (e.g. proxies of PyPI) emit anchors whose filename
309+
# does not parse as a valid PEP 427 wheel name (fewer than 4 `-`
310+
# separators). These should be skipped rather than crash downstream.
311+
input = struct(
312+
attrs = [
313+
'href="../../packages/six/1.16.0/six.whl#sha256=deadbeef"',
314+
],
315+
filename = "six.whl",
316+
)
317+
valid = struct(
318+
attrs = [
319+
'href="https://example.org/foo-0.0.1-py3-none-any.whl#sha256=cafefeed"',
320+
],
321+
filename = "foo-0.0.1-py3-none-any.whl",
322+
)
323+
html = _generate_html(input, valid)
324+
325+
got = parse_simpleapi_html(content = html, logger = _LOGGER)
326+
327+
env.expect.that_collection(got.whls).has_size(1)
328+
env.expect.that_collection(got.sdists).has_size(0)
329+
env.expect.that_str(got.whls["cafefeed"].filename).equals("foo-0.0.1-py3-none-any.whl")
330+
env.expect.that_collection(got.whls.keys()).contains_exactly(["cafefeed"])
331+
332+
_tests.append(_test_malformed_whl_anchor_is_skipped)
333+
307334
def parse_simpleapi_html_test_suite(name):
308335
"""Create the test suite.
309336

0 commit comments

Comments
 (0)