]> source.dussan.org Git - redmine.git/commitdiff
Comments for Textile text formatting (#20511).
authorGo MAEDA <maeda@farend.jp>
Thu, 17 Mar 2022 03:55:24 +0000 (03:55 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 17 Mar 2022 03:55:24 +0000 (03:55 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@21457 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 2816e1c90d9942742f91a988e6cdd8e4a5f8255b..dbb919ff178fa0dda6193d007bc212bb1618e4c0 100644 (file)
@@ -298,6 +298,7 @@ class RedCloth3 < String
         @pre_list = []
         rip_offtags text
         no_textile text
+        remove_html_comments text
         escape_html_tags text
         # need to do this before #hard_break and #blocks
         block_textile_quotes text unless @lite_mode
@@ -1217,4 +1218,8 @@ class RedCloth3 < String
             end
         end
     end
+
+    def remove_html_comments(text)
+        text.gsub!(/<!--[\s\S]*?-->/, '')
+    end
 end
index 20b854cc7552710403fd7fb99b0d5705d4365668..f34daf55a14cf64109995622db44d3b92a94aaaa 100644 (file)
@@ -1300,7 +1300,6 @@ class ApplicationHelperTest < Redmine::HelperTest
       "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
       "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
       "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
-      "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
       "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
       # remove attributes including class
       "<pre class='foo'>some text</pre>" => "<pre>some text</pre>",
index 8d9f4ce04e83bfe73dcdc5ff536899785c7b951a..30013b8370d36b2728fa2c0a2f055fe9b5c71644 100644 (file)
@@ -719,6 +719,38 @@ 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_remove_html_comments
+    text = <<~STR
+      <!-- begin -->
+      Hello <!-- comment between words -->world.
+
+      <!--
+        multi-line
+      comment -->Foo
+
+      <pre>
+      This is a code block.
+      <p>
+      <!-- comments in a code block should be preserved -->
+      </p>
+      </pre>
+    STR
+    expected = <<~EXPECTED
+      <p>Hello world.</p>
+
+      <p>Foo</p>
+
+      <pre>
+      This is a code block.
+      &lt;p&gt;
+      &lt;!-- comments in a code block should be preserved --&gt;
+      &lt;/p&gt;
+      </pre>
+
+    EXPECTED
+    assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '')
+  end
+
   private
 
   def assert_html_output(to_test, expect_paragraph = true)