From f847c3e75467ba929f6735de5ec02aa71dc60c97 Mon Sep 17 00:00:00 2001 From: wangb Date: Sun, 14 Jul 2024 00:20:55 +0800 Subject: [PATCH] fix: video poster image URL is encoded twice when using `MEDIA_PROXY_MODE=all` --- internal/mediaproxy/media_proxy_test.go | 25 +++++++++++++++++++++++++ internal/mediaproxy/rewriter.go | 15 +++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/internal/mediaproxy/media_proxy_test.go b/internal/mediaproxy/media_proxy_test.go index 2006fd6f..c142e578 100644 --- a/internal/mediaproxy/media_proxy_test.go +++ b/internal/mediaproxy/media_proxy_test.go @@ -553,3 +553,28 @@ func TestProxyFilterVideoPoster(t *testing.T) { t.Errorf(`Not expected output: got %s`, output) } } + +func TestProxyFilterVideoPosterOnce(t *testing.T) { + os.Clearenv() + os.Setenv("PROXY_OPTION", "all") + os.Setenv("PROXY_MEDIA_TYPES", "image,video") + os.Setenv("PROXY_PRIVATE_KEY", "test") + + var err error + parser := config.NewParser() + config.Opts, err = parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + r := mux.NewRouter() + r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy") + + input := `` + expected := `` + output := RewriteDocumentWithRelativeProxyURL(r, input) + + if expected != output { + t.Errorf(`Not expected output: got %s`, output) + } +} diff --git a/internal/mediaproxy/rewriter.go b/internal/mediaproxy/rewriter.go index b77be654..72db9848 100644 --- a/internal/mediaproxy/rewriter.go +++ b/internal/mediaproxy/rewriter.go @@ -4,6 +4,7 @@ package mediaproxy // import "miniflux.app/v2/internal/mediaproxy" import ( + "slices" "strings" "miniflux.app/v2/internal/config" @@ -53,13 +54,15 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, } }) - doc.Find("video").Each(func(i int, video *goquery.Selection) { - if posterAttrValue, ok := video.Attr("poster"); ok { - if shouldProxy(posterAttrValue, proxyOption) { - video.SetAttr("poster", proxifyFunction(router, posterAttrValue)) + if !slices.Contains(config.Opts.MediaProxyResourceTypes(), "video") { + doc.Find("video").Each(func(i int, video *goquery.Selection) { + if posterAttrValue, ok := video.Attr("poster"); ok { + if shouldProxy(posterAttrValue, proxyOption) { + video.SetAttr("poster", proxifyFunction(router, posterAttrValue)) + } } - } - }) + }) + } case "audio": doc.Find("audio, audio source").Each(func(i int, audio *goquery.Selection) {