diff --git a/lib/redmine/wiki_formatting/html_parser.rb b/lib/redmine/wiki_formatting/html_parser.rb index 62445ff3b..b3b45f590 100644 --- a/lib/redmine/wiki_formatting/html_parser.rb +++ b/lib/redmine/wiki_formatting/html_parser.rb @@ -30,7 +30,7 @@ module Redmine } def self.to_text(html) - html = html.gsub(/[\n\r]/, '').squeeze(' ') + html = html.gsub(/^\s+/, '').tr("\n\r", '').squeeze(' ') doc = Loofah.document(html) doc.scrub!(WikiTags.new(tags)) diff --git a/test/unit/lib/redmine/wiki_formatting/html_parser_test.rb b/test/unit/lib/redmine/wiki_formatting/html_parser_test.rb index 7900a5af8..bff38b1ed 100644 --- a/test/unit/lib/redmine/wiki_formatting/html_parser_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/html_parser_test.rb @@ -34,4 +34,9 @@ class Redmine::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase assert_equal "Text", @parser.to_text('Text') end + + def test_should_remove_preceding_whitespaces + assert_equal "foo\n\nbar", + @parser.to_text("
foo
\n

\n bar\n

") + end end