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

Ignore leading whitespace when checking for HTML doctype #10855

Closed
wants to merge 4 commits into from
Closed
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/10855.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Accept HTML files with whitespace before the doctype declaration.
11 changes: 10 additions & 1 deletion src/pip/_internal/index/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,16 @@ def parse_links(page: "HTMLPage", use_deprecated_html5lib: bool) -> Iterable[Lin
# requested to use html5lib.
if not use_deprecated_html5lib:
expected_doctype = "<!doctype html>".encode(encoding)
actual_start = page.content[: len(expected_doctype)]

char: int
offset: int = 0
for char in page.content:
if chr(char).isspace():
offset += 1
else:
break

actual_start = page.content[offset : offset + len(expected_doctype)]
if actual_start.decode(encoding).lower() != "<!doctype html>":
deprecated(
reason=(
Expand Down
4 changes: 4 additions & 0 deletions tests/data/indexes/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ for testing url quoting with indexes
simple
------
contains index page for "simple" pkg

indent
------
For testing indented HTML pages
6 changes: 6 additions & 0 deletions tests/data/indexes/indent/simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<a href="../../../packages/simple-1.0.tar.gz#md5=4bdf78ebb7911f215c1972cf71b378f0">simple-1.0.tar.gz</a>
</body>
</html>
11 changes: 11 additions & 0 deletions tests/functional/test_install_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ def test_file_index_url_quoting(script: PipTestEnvironment, data: TestData) -> N
result = script.pip("install", "-vvv", "--index-url", index_url, "simple")
result.did_create(script.site_packages / "simple")
result.did_create(script.site_packages / "simple-1.0.dist-info")


@pytest.mark.usefixtures("with_wheel")
def test_file_index_indent(script: PipTestEnvironment, data: TestData) -> None:
"""
Test url quoting of file index url with a space
"""
index_url = data.index_url(urllib.parse.quote("indent"))
result = script.pip("install", "-vvv", "--index-url", index_url, "simple")
result.did_create(script.site_packages / "simple")
result.did_create(script.site_packages / "simple-1.0.dist-info")