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.rbindex 94fd7e6bd4e..24c5cbf1a6b 100644--- a/app/models/admin_notice.rb+++ b/app/models/admin_notice.rb@@ -2,7 +2,7 @@class AdminNotice < ActiveRecord::BaseTRANSLATION_KEY_DETAIL = "_translation_key"- MESSAGE_ALLOWED_TAGS = %w[a pre ul li].freeze+ MESSAGE_ALLOWED_TAGS = %w[a code pre ul li].freezeMESSAGE_ALLOWED_ATTRIBUTES =(%w[href target rel] + SiteSettings::LabelFormatter::LINK_ATTRIBUTES).freezeMESSAGE_SANITIZER = Rails::Html::SafeListSanitizer.newdiff --git a/spec/models/admin_notice_spec.rb b/spec/models/admin_notice_spec.rbindex a1221ee4fd0..10e2de58914 100644--- a/spec/models/admin_notice_spec.rb+++ b/spec/models/admin_notice_spec.rb@@ -14,6 +14,12 @@ RSpec.describe AdminNotice doexpect(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" dostore_problem_translation("Configure {{setting:title}} to fix this")notice = Fabricate(:admin_notice, identifier: "test")