From a74b29769d5a7f7e185d74da1a808cb053352e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 21 Nov 2024 07:55:23 +0100 Subject: [PATCH 1/2] Do not treat HTML as inlinable --- app/models/attachment.rb | 6 +++++- spec/models/attachment_spec.rb | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b1d7ae1942c3..f1eb8ad9cae3 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -163,8 +163,12 @@ def is_pdf? content_type == "application/pdf" end + def is_html? + content_type == "text/html" + end + def is_text? - content_type.match?(/\Atext\/.+/) + content_type.match?(/\Atext\/.+/) && !is_html? end def is_diff? diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index cb061fcbab00..8afcc7b9c3b5 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -295,6 +295,17 @@ end end + describe "for an HTML file" do + let(:attachment) { described_class.new } + + it "assumes it to be inlineable" do + attachment.content_type = "text/html" + expect(attachment).to be_is_html + expect(attachment).not_to be_is_text + expect(attachment).not_to be_inlineable + end + end + describe "for a binary file" do before { binary_attachment.save! } From df6600dbabf8f7a735bbbf83277e56a3ed349828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 21 Nov 2024 09:02:46 +0100 Subject: [PATCH 2/2] Update spec/models/attachment_spec.rb Co-authored-by: Klaus Zanders --- spec/models/attachment_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index 8afcc7b9c3b5..91b249efa187 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -298,7 +298,7 @@ describe "for an HTML file" do let(:attachment) { described_class.new } - it "assumes it to be inlineable" do + it "assumes it not to be inlineable" do attachment.content_type = "text/html" expect(attachment).to be_is_html expect(attachment).not_to be_is_text