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

Properly yield results from html5lib parsing #10846

Merged
merged 1 commit into from
Jan 30, 2022
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
1 change: 1 addition & 0 deletions news/10846.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly handle links parsed by html5lib, when using ```--use-deprecated=html5lib``.
3 changes: 2 additions & 1 deletion src/pip/_internal/index/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def parse_links(page: "HTMLPage", use_deprecated_html5lib: bool) -> Iterable[Lin
Parse an HTML document, and yield its anchor elements as Link objects.
"""
if use_deprecated_html5lib:
return _parse_links_html5lib(page)
yield from _parse_links_html5lib(page)
return

parser = HTMLLinkParser()
encoding = page.encoding or "utf-8"
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,18 @@ def test_parse_links_caches_same_page_by_url() -> None:
assert "pkg2" in parsed_links_3[0].url


def test_parse_link_handles_deprecated_usage_properly() -> None:
html = b'<a href="/pkg1-1.0.tar.gz"><a href="/pkg1-2.0.tar.gz">'
url = "https://example.com/simple/"
page = HTMLPage(html, encoding=None, url=url)

parsed_links = list(parse_links(page, use_deprecated_html5lib=True))

assert len(parsed_links) == 2
assert "pkg1-1.0" in parsed_links[0].url
assert "pkg1-2.0" in parsed_links[1].url


@mock.patch("pip._internal.index.collector.raise_for_status")
def test_request_http_error(
mock_raise_for_status: mock.Mock, caplog: pytest.LogCaptureFixture
Expand Down