diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index a6dfd642181..78591ee2548 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -426,7 +426,7 @@ class CookedPostProcessor
informations = +"#{original_width}×#{original_height}"
informations << " #{upload.human_filesize}" if upload
- a["title"] = CGI.escapeHTML(img["title"] || filename)
+ a["title"] = CGI.escapeHTML(img["title"] || img["alt"] || filename)
meta.add_child create_icon_node("far-image")
meta.add_child create_span_node("filename", a["title"])
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 174c8b0ef5e..c1870ed6b1b 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -597,7 +597,38 @@ describe CookedPostProcessor do
end
- context "with title" do
+ context "with title and alt" do
+ fab!(:post) do
+ Fabricate(:post, raw: <<~HTML)
+
+ HTML
+ end
+
+ let(:cpp) { CookedPostProcessor.new(post, disable_loading_image: true) }
+
+ before do
+ SiteSetting.max_image_height = 2000
+ SiteSetting.create_thumbnails = true
+ FastImage.expects(:size).returns([1750, 2000])
+ OptimizedImage.expects(:resize).returns(true)
+ FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
+ end
+
+ it "generates overlay information using image title and ignores alt" do
+ cpp.post_process
+
+ expect(cpp.html).to match_html <<~HTML
+