fix-31232-v2.patch

Go MAEDA, 2019-04-21 04:16

Download (1.86 KB)

View differences:

lib/redmine/wiki_formatting/html_parser.rb
30 30
      }
31 31

  
32 32
      def self.to_text(html)
33
        html = html.gsub(/[\n\r]/, '').squeeze(' ')
33
        html = html.gsub(/[\n\r]/, ' ')
34 34
    
35 35
        doc = Loofah.document(html)
36 36
        doc.scrub!(WikiTags.new(tags))
37 37
        doc.scrub!(:newline_block_elements)
38 38
    
39
        Loofah::Helpers.remove_extraneous_whitespace(doc.text).strip
39
        Loofah::Helpers.remove_extraneous_whitespace(doc.text).strip.squeeze(' ').gsub(/^ /, '')
40 40
      end
41 41

  
42 42
      class WikiTags < ::Loofah::Scrubber
test/unit/lib/redmine/wiki_formatting/html_parser_test.rb
34 34
    assert_equal "Text",
35 35
      @parser.to_text('<html><body><style>body {font-size: 0.8em;}</style>Text</body></html>')
36 36
  end
37

  
38
  def test_should_remove_preceding_whitespaces
39
    to_test = {
40
      "<div>  blocks with</div>\n<p>\n  preceding whitespaces\n</p>" => "blocks with\n\npreceding whitespaces",
41
      "<div>blocks without</div>\n<p>\npreceding whitespaces\n</p>" => "blocks without\n\npreceding whitespaces",
42
      "<span>  span with</span>\n<span>  preceding whitespaces</span>" => "span with preceding whitespaces",
43
      "<span>span without</span>\n<span>preceding whitespaces</span>" => "span without preceding whitespaces"
44
    }
45
    to_test.each do |html, expected|
46
      assert_equal expected, @parser.to_text(html)
47
    end
48
  end
37 49
end