]> source.dussan.org Git - redmine.git/commitdiff
Merged r21902 from trunk to 4.2-stable (#37767).
authorGo MAEDA <maeda@farend.jp>
Mon, 17 Oct 2022 13:59:56 +0000 (13:59 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 17 Oct 2022 13:59:56 +0000 (13:59 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21904 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/wiki_formatting/textile/redcloth3.rb
test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb

index 34774310557b833cde0fe202dad6f81659770a3e..532283e7ee8e9eca26b81fdda3c2c3ffe606a4a0 100644 (file)
@@ -1207,13 +1207,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
index 28a3d92aba216197a7884b2361d026abfd4d1749..2cf06680e94b2911ccdb72650e7c3b7d763ca147 100644 (file)
@@ -703,6 +703,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_escape_bq_citations
     assert_html_output({
       %{bq.:http://x/"onmouseover="alert(document.domain) Hover me} =>