fix(images): percent-encode original-image URLs ('#' in paths 404'd)
An image whose on-disk path contains '#' (post folders like 'BLUE#59') served its hash-named thumbnail fine but 404'd the original: the unencoded '#' in image_url was parsed by the browser as a URL fragment, so '#59/01_timelapse.jpg' never reached the /images route. Add a shared image_url(path) helper that percent-encodes the path (safe='/') and route the 3 raw builders (gallery detail + 2 in series) through it. Not a cleanup-tool deletion — the file is on disk; only the URL was wrong. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,11 +8,22 @@ from backend.app.services.gallery_service import (
|
||||
GalleryService,
|
||||
decode_cursor,
|
||||
encode_cursor,
|
||||
image_url,
|
||||
)
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
def test_image_url_percent_encodes_special_chars():
|
||||
# A '#' in a post folder ('BLUE#59') would otherwise be parsed as a URL
|
||||
# fragment, dropping the rest of the path and 404'ing the original while the
|
||||
# hash-named thumbnail still loads. Operator-flagged 2026-06-12.
|
||||
url = image_url("/images/dismassd/patreon/2024-04-28_BLUE#59/01 a.jpg")
|
||||
assert url == "/images/dismassd/patreon/2024-04-28_BLUE%2359/01%20a.jpg"
|
||||
# '/' stays a separator; a plain path is unchanged.
|
||||
assert image_url("/images/a/b/c.jpg") == "/images/a/b/c.jpg"
|
||||
|
||||
|
||||
def _now():
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user