From 70ecfe59ffa6f5a2937545a33e5af1eab5bbdab3 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 23 Apr 2026 13:57:30 -0400 Subject: [PATCH] fix(utils): URL-encode media paths to handle special characters in filenames Cover image URLs with special characters like parentheses, #, ?, or spaces would break because browsers interpret them as URL delimiters. Apply url.PathEscape() per path segment in ResolveMediaURL so the server can correctly resolve files like "Wonder Woman (2016) #001.cbz.cover.jpg". Also adds a package doc comment and fixes the exported function comment. --- internal/utils/mediaurl.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/utils/mediaurl.go b/internal/utils/mediaurl.go index 542b6ba..e03900a 100644 --- a/internal/utils/mediaurl.go +++ b/internal/utils/mediaurl.go @@ -1,7 +1,9 @@ +// Package utils provides helper functions for URL resolution, ISBN handling, and tag management. package utils import ( "fmt" + "net/url" "path/filepath" "strings" @@ -9,7 +11,7 @@ import ( "github.com/jackc/pgx/v5/pgtype" ) -// resolveMediaURL resolves a relative path (cover or file) to a full URL +// ResolveMediaURL resolves a relative path (cover or file) to a full URL func ResolveMediaURL(libraryID pgtype.UUID, relativePath pgtype.Text) string { if !relativePath.Valid || relativePath.String == "" { return "" @@ -24,5 +26,10 @@ func ResolveMediaURL(libraryID pgtype.UUID, relativePath pgtype.Text) string { } libraryIDStr := uuid.UUID(libraryID.Bytes).String() - return fmt.Sprintf("/uploads/library-%s/%s", libraryIDStr, relativePath.String) + segments := strings.Split(relativePath.String, "/") + for i, seg := range segments { + segments[i] = url.PathEscape(seg) + } + encodedPath := strings.Join(segments, "/") + return fmt.Sprintf("/uploads/library-%s/%s", libraryIDStr, encodedPath) }