Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Do not treat HTML as inlinable

Oliver Günthera74b29769d5a
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index b1d7ae1942c..f1eb8ad9cae 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -163,8 +163,12 @@ class Attachment < ApplicationRecord
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 cb061fcbab0..8afcc7b9c3b 100644
--- a/spec/models/attachment_spec.rb
+++ b/spec/models/attachment_spec.rb
@@ -295,6 +295,17 @@ RSpec.describe Attachment do
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! }