Skip to content

Commit f87e97d

Browse files
authored
Quote-encode backfill URLs (#15503)
1 parent 6c84303 commit f87e97d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

tests/unit/packaging/test_tasks.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,24 @@ def test_metadata_backfill(db_request, monkeypatch, metrics):
930930
]
931931

932932

933-
def test_metadata_backfill_individual(db_request, monkeypatch, metrics):
933+
@pytest.mark.parametrize(
934+
"path, requested_path",
935+
[
936+
# Regular path
937+
(
938+
"8a/6a/19...3b/pip-24.0-py3-none-any.whl",
939+
"8a/6a/19...3b/pip-24.0-py3-none-any.whl",
940+
),
941+
# Path with characters that need quoted
942+
(
943+
"da/5d/cc...0d/scalg-0.1.1#-py3-none-any.whl",
944+
"da/5d/cc...0d/scalg-0.1.1%23-py3-none-any.whl",
945+
),
946+
],
947+
)
948+
def test_metadata_backfill_individual(
949+
db_request, monkeypatch, metrics, path, requested_path
950+
):
934951
project = ProjectFactory()
935952
release1 = ReleaseFactory(project=project)
936953
release2 = ReleaseFactory(project=project)
@@ -942,7 +959,10 @@ def test_metadata_backfill_individual(db_request, monkeypatch, metrics):
942959
)
943960
FileFactory(release=release2, packagetype="sdist")
944961
backfillable_file = FileFactory(
945-
release=release2, packagetype="bdist_wheel", metadata_file_sha256_digest=None
962+
release=release2,
963+
packagetype="bdist_wheel",
964+
metadata_file_sha256_digest=None,
965+
path=path,
946966
)
947967

948968
metadata_contents = b"some\nmetadata\ncontents"
@@ -996,7 +1016,7 @@ def mock_open(filename, perms):
9961016
assert dist_from_wheel_url.calls == [
9971017
pretend.call(
9981018
project.normalized_name,
999-
f"https://files.example.com/packages/{backfillable_file.path}",
1019+
f"https://files.example.com/packages/{requested_path}",
10001020
stub_session,
10011021
)
10021022
]

warehouse/packaging/tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
import os
1717
import tempfile
18+
import urllib.parse
1819

1920
from collections import namedtuple
2021
from itertools import product
@@ -95,7 +96,7 @@ def metadata_backfill_individual(request, file_id):
9596
return
9697

9798
base_url = request.registry.settings.get("files.url")
98-
file_url = base_url.format(path=file_.path)
99+
file_url = urllib.parse.quote(base_url.format(path=file_.path), safe=":/")
99100
metrics = request.find_service(IMetricsService, context=None)
100101
cache_storage = request.find_service(IFileStorage, name="cache")
101102
archive_storage = request.find_service(IFileStorage, name="archive")

0 commit comments

Comments
 (0)