From cf1d0c5e7cb2f8d6769a25991979e4dca3f2d988 Mon Sep 17 00:00:00 2001 From: Tim Hatch Date: Tue, 27 Feb 2024 10:05:28 -0800 Subject: [PATCH 1/3] Just hash metadata as bytes. Because warehouse doesn't send a charset, this can get decoded as something other than utf-8, which doesn't encode (as utf-8) back to the same bytes. For hash purposes especially, just look at the original bytes. --- src/poetry/repositories/http_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/repositories/http_repository.py b/src/poetry/repositories/http_repository.py index db7a365405c..515907e72e5 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -169,7 +169,7 @@ def _get_info_from_metadata(self, link: Link) -> PackageInfo | None: ) ): metadata_hash = getattr(hashlib, hash_name)( - response.text.encode() + response.content ).hexdigest() if metadata_hash != link.metadata_hashes[hash_name]: self._log( From 907ce9350bbba5af542de1ce5fec039274e3abe6 Mon Sep 17 00:00:00 2001 From: Tim Hatch Date: Tue, 27 Feb 2024 10:16:56 -0800 Subject: [PATCH 2/3] Modify isort-metadata test to be invalid utf-8 This ensures that it remains bytes the whole way through. --- tests/repositories/conftest.py | 3 +-- tests/repositories/fixtures/legacy/isort-metadata.html | 2 +- .../metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/repositories/conftest.py b/tests/repositories/conftest.py index 1f9a6d11946..a6793e6ba58 100644 --- a/tests/repositories/conftest.py +++ b/tests/repositories/conftest.py @@ -50,8 +50,7 @@ def metadata_mock(url: str, **__: Any) -> requests.Response: / "metadata" / posixpath.basename(url) ) - .read_text() - .encode() + .read_bytes() ) return response raise requests.HTTPError() diff --git a/tests/repositories/fixtures/legacy/isort-metadata.html b/tests/repositories/fixtures/legacy/isort-metadata.html index 699a13e0192..4a72ba6863c 100644 --- a/tests/repositories/fixtures/legacy/isort-metadata.html +++ b/tests/repositories/fixtures/legacy/isort-metadata.html @@ -6,7 +6,7 @@

Links for isort

isort-metadata-4.3.4-py3-none-any.whl
+ data-dist-info-metadata="sha256=032d41ef93ff20e432cdc1f9cea7918458ae93ddbfea63d7d11b1eaf1915c430">isort-metadata-4.3.4-py3-none-any.whl
diff --git a/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata b/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata index bab8d017156..376f96c5aa8 100644 --- a/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata +++ b/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata @@ -26,3 +26,4 @@ Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Utilities Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* Requires-Dist: futures; python_version=="2.7" +€ \ No newline at end of file From 4d9b0716c62b376e6f6b1bb0f259c80444ae97bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 2 Mar 2024 06:49:27 +0100 Subject: [PATCH 3/3] Revert "Modify isort-metadata test to be invalid utf-8" --- tests/repositories/conftest.py | 3 ++- tests/repositories/fixtures/legacy/isort-metadata.html | 2 +- .../metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/repositories/conftest.py b/tests/repositories/conftest.py index a6793e6ba58..1f9a6d11946 100644 --- a/tests/repositories/conftest.py +++ b/tests/repositories/conftest.py @@ -50,7 +50,8 @@ def metadata_mock(url: str, **__: Any) -> requests.Response: / "metadata" / posixpath.basename(url) ) - .read_bytes() + .read_text() + .encode() ) return response raise requests.HTTPError() diff --git a/tests/repositories/fixtures/legacy/isort-metadata.html b/tests/repositories/fixtures/legacy/isort-metadata.html index 4a72ba6863c..699a13e0192 100644 --- a/tests/repositories/fixtures/legacy/isort-metadata.html +++ b/tests/repositories/fixtures/legacy/isort-metadata.html @@ -6,7 +6,7 @@

Links for isort

isort-metadata-4.3.4-py3-none-any.whl
+ data-dist-info-metadata="sha256=e360bf0ed8a06390513d50dd5b7e9d635c789853a93b84163f9de4ae0647580c">isort-metadata-4.3.4-py3-none-any.whl
diff --git a/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata b/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata index 376f96c5aa8..bab8d017156 100644 --- a/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata +++ b/tests/repositories/fixtures/metadata/isort-metadata-4.3.4-py3-none-any.whl.metadata @@ -26,4 +26,3 @@ Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Utilities Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* Requires-Dist: futures; python_version=="2.7" -€ \ No newline at end of file