Skip to content

Commit 6a9ea31

Browse files
committed
convert hashes to lowercase prior to comparisons
1 parent 66f4a5d commit 6a9ea31

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

news/12680.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Perform hash comparisons in a case-insensitive manner.

src/pip/_internal/utils/hashes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, hashes: Optional[Dict[str, List[str]]] = None) -> None:
3333
if hashes is not None:
3434
for alg, keys in hashes.items():
3535
# Make sure values are always sorted (to ease equality checks)
36-
allowed[alg] = sorted(keys)
36+
allowed[alg] = [k.lower() for k in sorted(keys)]
3737
self._allowed = allowed
3838

3939
def __and__(self, other: "Hashes") -> "Hashes":

tests/functional/test_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ def test_incorrect_metadata_hash(
14011401
)
14021402
assert result.returncode != 0
14031403
expected_msg = f"""\
1404-
Expected sha256 WRONG-HASH
1404+
Expected sha256 wrong-hash
14051405
Got {real_hash}"""
14061406
assert expected_msg in result.stderr
14071407

tests/functional/test_install.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,18 @@ def test_hashed_install_failure(script: PipTestEnvironment, tmpdir: Path) -> Non
619619
assert len(result.files_created) == 0
620620

621621

622+
def test_case_insensitive_hashed_install_success(
623+
script: PipTestEnvironment, tmpdir: Path
624+
) -> None:
625+
"""Test that hashes that differ only by case don't halt installation."""
626+
with requirements_file(
627+
"simple2==1.0 --hash=sha256:9336AF72CA661E6336EB87BC7DE3E8844D853E"
628+
"3848C2B9BBD2E8BF01DB88C2C7\n",
629+
tmpdir,
630+
) as reqs_file:
631+
script.pip_install_local("-r", reqs_file.resolve())
632+
633+
622634
def test_link_hash_pass_require_hashes(
623635
script: PipTestEnvironment, shared_data: TestData
624636
) -> None:

0 commit comments

Comments
 (0)