Skip to content

Commit

Permalink
perform case-insensitive hash comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrodrigues committed May 25, 2024
1 parent fb71f4c commit 65da1f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/12680.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Perform hash comparisons in a case-insensitive manner.
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def check_against_chunks(self, chunks: Iterable[bytes]) -> None:
hash.update(chunk)

for hash_name, got in gots.items():
if got.hexdigest() in self._allowed[hash_name]:
if got.hexdigest() in [x.lower() for x in self._allowed[hash_name]]:
return
self._raise(gots)

Expand Down
12 changes: 12 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,18 @@ def test_hashed_install_failure(script: PipTestEnvironment, tmpdir: Path) -> Non
assert len(result.files_created) == 0


def test_case_insensitive_hashed_install_success(
script: PipTestEnvironment, tmpdir: Path
) -> None:
"""Test that hashes that differ only by case don't halt installation."""
with requirements_file(
"simple2==1.0 --hash=sha256:9336AF72CA661E6336EB87BC7DE3E8844D853E"
"3848C2B9BBD2E8BF01DB88C2C7\n",
tmpdir,
) as reqs_file:
script.pip_install_local("-r", reqs_file.resolve())


def test_link_hash_pass_require_hashes(
script: PipTestEnvironment, shared_data: TestData
) -> None:
Expand Down

0 comments on commit 65da1f9

Please sign in to comment.