diff options
-rw-r--r-- | changelogs/unreleased/sh-revert-markdown-changes.yml | 5 | ||||
-rw-r--r-- | lib/banzai/filter/sanitization_filter.rb | 17 |
2 files changed, 17 insertions, 5 deletions
diff --git a/changelogs/unreleased/sh-revert-markdown-changes.yml b/changelogs/unreleased/sh-revert-markdown-changes.yml new file mode 100644 index 00000000000..72540f710a1 --- /dev/null +++ b/changelogs/unreleased/sh-revert-markdown-changes.yml @@ -0,0 +1,5 @@ +--- +title: Fix slow Markdown rendering +merge_request: 20820 +author: +type: performance diff --git a/lib/banzai/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb index 80b9d3d045f..80a5394dc12 100644 --- a/lib/banzai/filter/sanitization_filter.rb +++ b/lib/banzai/filter/sanitization_filter.rb @@ -6,20 +6,27 @@ module Banzai # # Extends HTML::Pipeline::SanitizationFilter with a custom whitelist. class SanitizationFilter < HTML::Pipeline::SanitizationFilter - include Gitlab::Utils::StrongMemoize - UNSAFE_PROTOCOLS = %w(data javascript vbscript).freeze TABLE_ALIGNMENT_PATTERN = /text-align: (?<alignment>center|left|right)/ def whitelist - strong_memoize(:whitelist) do - customize_whitelist(super.dup) - end + whitelist = super.dup + + customize_whitelist(whitelist) + + whitelist end private + def customized?(transformers) + transformers.last.source_location[0] == __FILE__ + end + def customize_whitelist(whitelist) + # Only push these customizations once + return if customized?(whitelist[:transformers]) + # Allow table alignment; we whitelist specific text-align values in a # transformer below whitelist[:attributes]['th'] = %w(style) |