1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-31 11:37:14 +00:00

Escape tags that start with pre (#37767).

Patch by Holger Just.


git-svn-id: https://svn.redmine.org/redmine/trunk@21902 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2022-10-17 13:35:20 +00:00
parent 823080b45e
commit 1d9f5c6742
2 changed files with 18 additions and 5 deletions

View File

@ -1208,13 +1208,15 @@ class RedCloth3 < String
end
end
ALLOWED_TAGS = %w(redpre pre code kbd notextile)
ALLOWED_TAGS = %w(pre code kbd notextile)
def escape_html_tags(text)
text.gsub!(%r{<(\/?([!\w]+)[^<>\n]*)(>?)}) do |m|
if ALLOWED_TAGS.include?($2) && $3.present?
"<#{$1}#{$3}"
text.gsub!(%r{<(\/?([!\w][^ >\t\f\r\n]*)[^<>\n]*)(>?)}) do |m|
all, tag, close = $1, $2, $3
if close.present? && (ALLOWED_TAGS.include?(tag) || (tag =~ /\Aredpre#\d+\z/))
"<#{all}#{close}"
else
"&lt;#{$1}#{'&gt;' unless $3.blank?}"
"&lt;#{all}#{'&gt;' unless close.blank?}"
end
end
end

View File

@ -719,6 +719,17 @@ class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '')
end
def test_should_escape_tags_that_start_with_pre
text = <<~STR
<preä demo>Text
STR
expected = <<~EXPECTED
<p>&lt;preä demo&gt;Text</p>
EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '')
end
def test_should_remove_html_comments
text = <<~STR
<!-- begin -->