diff --git a/archivebox/core/views.py b/archivebox/core/views.py
index 122ad87c..62a64f14 100644
--- a/archivebox/core/views.py
+++ b/archivebox/core/views.py
@@ -575,7 +575,7 @@ class SnapshotView(View):
slug,
)
+ snapshot_hrefs
- + format_html('
Choose a Snapshot to proceed or go back to the Main Index'),
+ + mark_safe('
Choose a Snapshot to proceed or go back to the Main Index'),
content_type="text/html",
status=404,
)
@@ -677,7 +677,7 @@ class SnapshotView(View):
base_url(path),
)
+ snapshot_hrefs
- + format_html('
Choose a Snapshot to proceed or go back to the Main Index'),
+ + mark_safe('
Choose a Snapshot to proceed or go back to the Main Index'),
content_type="text/html",
status=404,
)
diff --git a/archivebox/tests/test_ui_public_snapshot.py b/archivebox/tests/test_ui_public_snapshot.py
index e54772c1..1cdb08d4 100644
--- a/archivebox/tests/test_ui_public_snapshot.py
+++ b/archivebox/tests/test_ui_public_snapshot.py
@@ -181,6 +181,7 @@ def _create_public_snapshot_with_cli(data_dir, url: str) -> str:
timeout=60,
)
assert result.returncode == 0, result.stderr or result.stdout
+
records = [json.loads(line) for line in result.stdout.splitlines() if line.strip().startswith("{")]
assert records, result.stdout
snapshot_id = str(records[-1]["id"])
@@ -207,6 +208,25 @@ def _create_public_snapshot_with_cli(data_dir, url: str) -> str:
return snapshot_id
+@override_settings(PUBLIC_INDEX=True)
+def test_archive_url_with_multiple_snapshots_shows_snapshot_picker(client, admin_user):
+ from archivebox.core.models import Snapshot
+ from archivebox.crawls.models import Crawl
+
+ url = "https://multiple-public-snapshots.example/page"
+ first_crawl = Crawl.objects.create(urls=url, created_by=admin_user, config={"PERMISSIONS": "public"})
+ second_crawl = Crawl.objects.create(urls=url, created_by=admin_user, config={"PERMISSIONS": "public"})
+ first = Snapshot.objects.create(url=url, title="First copy", crawl=first_crawl, status=Snapshot.StatusChoices.SEALED)
+ second = Snapshot.objects.create(url=url, title="Second copy", crawl=second_crawl, status=Snapshot.StatusChoices.SEALED)
+
+ response = client.get(f"/archive/{url}", HTTP_HOST=WEB_TEST_HOST)
+
+ assert response.status_code == 404
+ assert b"Multiple Snapshots match the given URL" in response.content
+ assert first.archive_path.encode() in response.content
+ assert second.archive_path.encode() in response.content
+
+
def _login_admin_session_over_http(port: int, host: str) -> requests.Session:
session = requests.Session()
login_page = session.get(