Project

General

Profile

Patch #42737 » 0001-If-not-needed-stop-traverse.patch

Takashi Kato, 2026-02-06 00:03

View differences:

lib/redmine/wiki_formatting/common_mark/formatter.rb
SANITIZER = SanitizationFilter.new
SCRUBBERS = [
Redmine::WikiFormatting::CopypreScrubber.new,
SyntaxHighlightScrubber.new,
Redmine::WikiFormatting::TablesortScrubber.new,
Redmine::WikiFormatting::CopypreScrubber.new,
FixupAutoLinksScrubber.new,
ExternalLinksScrubber.new,
AlertsIconsScrubber.new
......
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|
result = s.scrub(node)
break result if result == Loofah::Scrubber::STOP
break if node.parent.nil?
end
end
fragment.scrub!(scrubber)
fragment.to_s
end
end
lib/redmine/wiki_formatting/common_mark/syntax_highlight_scrubber.rb
lang = $1
text = node.inner_text
process node, text, lang
Loofah::Scrubber::STOP
end
end
end
lib/redmine/wiki_formatting/html_sanitizer.rb
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|
result = s.scrub(node)
break result if result == Loofah::Scrubber::STOP
break if node.parent.nil?
end
end
fragment.scrub!(scrubber)
fragment.to_s
end
end
lib/redmine/wiki_formatting/textile/formatter.rb
module WikiFormatting
module Textile
SCRUBBERS = [
Redmine::WikiFormatting::CopypreScrubber.new,
SyntaxHighlightScrubber.new,
Redmine::WikiFormatting::TablesortScrubber.new,
Redmine::WikiFormatting::CopypreScrubber.new
Redmine::WikiFormatting::TablesortScrubber.new
]
class Formatter
......
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|
result = s.scrub(node)
break result if result == Loofah::Scrubber::STOP
break if node.parent.nil?
end
end
fragment.scrub!(scrubber)
fragment.to_s
end
end
lib/redmine/wiki_formatting/textile/syntax_highlight_scrubber.rb
end
process node, text, lang
Loofah::Scrubber::STOP
end
end
end
test/helpers/application_helper_test.rb
end
end
def test_syntax_highlight_common_mark
raw = <<~RAW
```ECMA_script
/* Hello */
document.write("Hello World!");
```
RAW
expected = <<~EXPECTED
#{pre_wrapper('<pre data-clipboard-target="pre"><code class="ECMA_script syntaxhl" data-language="ECMA_script"><span class="cm">/* Hello */</span><span class="nb">document</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="dl">"</span><span class="s2">Hello World!</span><span class="dl">"</span><span class="p">);</span></code></pre>')}
EXPECTED
with_settings :text_formatting => 'common_mark' do
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
end
end
def test_syntax_highlight_ampersand_in_textile
raw = <<~RAW
<pre><code class="ruby">
(4-4/4)