]> source.dussan.org Git - redmine.git/commitdiff
Text may unexpectedly be enclosed in pre tags when an issue is created via HTML email...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 20 Jun 2019 06:38:19 +0000 (06:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 20 Jun 2019 06:38:19 +0000 (06:38 +0000)
Patch by Go MAEDA.

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

lib/redmine/wiki_formatting/html_parser.rb
test/unit/lib/redmine/wiki_formatting/html_parser_test.rb

index aa4891ce09dc59bdf66d43fee2968fecef3f9c49..80f15b72ca90e2d89b366df0777b38d2e0c7feb4 100644 (file)
@@ -30,13 +30,13 @@ module Redmine
       }
 
       def self.to_text(html)
-        html = html.gsub(/[\n\r]/, '').squeeze(' ')
+        html = html.gsub(/[\n\r]/, ' ')
 
         doc = Loofah.document(html)
         doc.scrub!(WikiTags.new(tags))
         doc.scrub!(:newline_block_elements)
 
-        Loofah.remove_extraneous_whitespace(doc.text).strip
+        Loofah.remove_extraneous_whitespace(doc.text).strip.squeeze(' ').gsub(/^ +/, '')
       end
 
       class WikiTags < ::Loofah::Scrubber
index 7224f697d8051dcd05e5794f40ba84a273629601..210bba8325ef96841dd41478816faf8f13a0ff5d 100644 (file)
@@ -34,4 +34,16 @@ class Redmine::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase
     assert_equal "Text",
       @parser.to_text('<html><body><style>body {font-size: 0.8em;}</style>Text</body></html>')
   end
+
+  def test_should_remove_preceding_whitespaces
+    to_test = {
+      "<div>  blocks with</div>\n<p>\n  preceding whitespaces\n</p>" => "blocks with\n\npreceding whitespaces",
+      "<div>blocks without</div>\n<p>\npreceding whitespaces\n</p>" => "blocks without\n\npreceding whitespaces",
+      "<span>  span with</span>\n<span>  preceding whitespaces</span>" => "span with preceding whitespaces",
+      "<span>span without</span>\n<span>preceding whitespaces</span>" => "span without preceding whitespaces"
+    }
+    to_test.each do |html, expected|
+      assert_equal expected, @parser.to_text(html)
+    end
+  end
 end