Optimize Loofah performance by passing the HTML only once (#42737).

git-svn-id: https://svn.redmine.org/redmine/trunk@24399 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu
2026-02-07 10:27:50 +00:00
parent 3d8c1f01a4
commit a56413532c
3 changed files with 18 additions and 6 deletions

View File

@@ -73,9 +73,13 @@ module Redmine
html = MarkdownFilter.new(@text, PIPELINE_CONFIG).call
fragment = Redmine::WikiFormatting::HtmlParser.parse(html)
SANITIZER.call(fragment)
SCRUBBERS.each do |scrubber|
fragment.scrub!(scrubber)
scrubber = Loofah::Scrubber.new do |node|
SCRUBBERS.each do |s|
s.scrub(node)
break if node.parent.nil?
end
end
fragment.scrub!(scrubber)
fragment.to_s
end
end

View File

@@ -27,9 +27,13 @@ module Redmine
def self.call(html)
fragment = HtmlParser.parse(html)
SANITIZER.call(fragment)
SCRUBBERS.each do |scrubber|
fragment.scrub!(scrubber)
scrubber = Loofah::Scrubber.new do |node|
SCRUBBERS.each do |s|
s.scrub(node)
break if node.parent.nil?
end
end
fragment.scrub!(scrubber)
fragment.to_s
end
end

View File

@@ -39,9 +39,13 @@ module Redmine
def to_html(*rules)
html = @filter.to_html(rules)
fragment = Loofah.html5_fragment(html)
SCRUBBERS.each do |scrubber|
fragment.scrub!(scrubber)
scrubber = Loofah::Scrubber.new do |node|
SCRUBBERS.each do |s|
s.scrub(node)
break if node.parent.nil?
end
end
fragment.scrub!(scrubber)
fragment.to_s
end
end