diff options
-rw-r--r-- | lib/redmine/wiki_formatting/textile/redcloth3.rb | 5 | ||||
-rw-r--r-- | test/helpers/application_helper_test.rb | 1 | ||||
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb | 32 |
3 files changed, 37 insertions, 1 deletions
diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb index 2816e1c90..dbb919ff1 100644 --- a/lib/redmine/wiki_formatting/textile/redcloth3.rb +++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb @@ -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 diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 20b854cc7..f34daf55a 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -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><div>content</div></pre>", - "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", "<!-- opening comment" => "<p><!-- opening comment</p>", # remove attributes including class "<pre class='foo'>some text</pre>" => "<pre>some text</pre>", diff --git a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb index 8d9f4ce04..30013b837 100644 --- a/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/textile_formatter_test.rb @@ -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. + <p> + <!-- comments in a code block should be preserved --> + </p> + </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) |