Skip to content

A platform for community discussion. Free, open, simple.

UX: Allow `code` tags in admin notice messages

Régis Hanolb6ee5649303f
diff --git a/app/models/admin_notice.rb b/app/models/admin_notice.rb
index 94fd7e6bd4e..24c5cbf1a6b 100644
--- a/app/models/admin_notice.rb
+++ b/app/models/admin_notice.rb
@@ -2,7 +2,7 @@
class AdminNotice < ActiveRecord::Base
TRANSLATION_KEY_DETAIL = "_translation_key"
- MESSAGE_ALLOWED_TAGS = %w[a pre ul li].freeze
+ MESSAGE_ALLOWED_TAGS = %w[a code pre ul li].freeze
MESSAGE_ALLOWED_ATTRIBUTES =
(%w[href target rel] + SiteSettings::LabelFormatter::LINK_ATTRIBUTES).freeze
MESSAGE_SANITIZER = Rails::Html::SafeListSanitizer.new
diff --git a/spec/models/admin_notice_spec.rb b/spec/models/admin_notice_spec.rb
index a1221ee4fd0..10e2de58914 100644
--- a/spec/models/admin_notice_spec.rb
+++ b/spec/models/admin_notice_spec.rb
@@ -14,6 +14,12 @@ RSpec.describe AdminNotice do
expect(notice.message).to eq("Something is wrong with the world")
end
+ it "keeps allowed tags and strips the others" do
+ store_problem_translation("Rename <code>%{old}</code> <b>now</b>")
+ notice = Fabricate(:admin_notice, identifier: "test", details: { old: "a/b" })
+ expect(notice.message).to eq("Rename <code>a/b</code> now")
+ end
+
it "expands setting markers into links that survive sanitization" do
store_problem_translation("Configure {{setting:title}} to fix this")
notice = Fabricate(:admin_notice, identifier: "test")