diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index f0e3537ebf6..ffeffe788e0 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -415,7 +415,10 @@ class CookedPostProcessor %w{src data-small-upload}.each do |selector| @doc.css("img[#{selector}]").each do |img| - img[selector] = UrlHelper.cook_url(img[selector].to_s, secure: @post.with_secure_media?) + custom_emoji = img["class"]&.include?("emoji-custom") && Emoji.custom?(img["title"]) + img[selector] = UrlHelper.cook_url( + img[selector].to_s, secure: @post.with_secure_media? && !custom_emoji + ) end end end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 809b63555ac..9de2d5b6287 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -1359,6 +1359,26 @@ describe CookedPostProcessor do HTML end + it "doesn't use the secure media URL for custom emoji" do + CustomEmoji.create!(name: 'trout', upload: upload) + Emoji.clear_cache + Emoji.load_custom + stored_path = Discourse.store.get_path_for_upload(upload) + upload.update_column(:url, "#{SiteSetting.Upload.absolute_base_url}/#{stored_path}") + upload.update_column(:secure, true) + + the_post = Fabricate(:post, raw: "This post has a custom emoji :trout:") + the_post.cook(the_post.raw) + + cpp = CookedPostProcessor.new(the_post) + cpp.optimize_urls + + upload_url = upload.url.gsub(SiteSetting.Upload.absolute_base_url, "https://s3.cdn.com") + expect(cpp.html).to match_html <<~HTML +

This post has a custom emoji :trout:

+ HTML + end + context "media uploads" do fab!(:image_upload) { Fabricate(:upload) } fab!(:audio_upload) { Fabricate(:upload, extension: "ogg") }