From e911ce7cb41c3fce7d78f7032f2772b7061446bf 2015-06-16 18:23:25 From: Jean-Philippe Lang Date: 2015-06-16 18:23:25 Subject: [PATCH] Remove style tags from html body (#15716). git-svn-id: http://svn.redmine.org/redmine/trunk@14315 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/wiki_formatting/html_parser.rb b/lib/redmine/wiki_formatting/html_parser.rb index 9d83497..a81d9d9 100644 --- a/lib/redmine/wiki_formatting/html_parser.rb +++ b/lib/redmine/wiki_formatting/html_parser.rb @@ -23,7 +23,8 @@ module Redmine class_attribute :tags self.tags = { - 'br' => {:post => "\n"} + 'br' => {:post => "\n"}, + 'style' => '' } def self.to_text(html) @@ -44,9 +45,16 @@ module Redmine def scrub(node) formatting = @tags_to_text[node.name] - return CONTINUE unless formatting - node.add_next_sibling Nokogiri::XML::Text.new("#{formatting[:pre]}#{node.content}#{formatting[:post]}", node.document) - node.remove + case formatting + when Hash + node.add_next_sibling Nokogiri::XML::Text.new("#{formatting[:pre]}#{node.content}#{formatting[:post]}", node.document) + node.remove + when String + node.add_next_sibling Nokogiri::XML::Text.new(formatting, node.document) + node.remove + else + CONTINUE + end end end end diff --git a/lib/redmine/wiki_formatting/markdown/html_parser.rb b/lib/redmine/wiki_formatting/markdown/html_parser.rb index 14f8937..e2dd1a7 100644 --- a/lib/redmine/wiki_formatting/markdown/html_parser.rb +++ b/lib/redmine/wiki_formatting/markdown/html_parser.rb @@ -32,7 +32,8 @@ module Redmine 'h3' => {:pre => "\n\n### ", :post => "\n\n"}, 'h4' => {:pre => "\n\n#### ", :post => "\n\n"}, 'h5' => {:pre => "\n\n##### ", :post => "\n\n"}, - 'h6' => {:pre => "\n\n###### ", :post => "\n\n"} + 'h6' => {:pre => "\n\n###### ", :post => "\n\n"}, + 'style' => '' } end end diff --git a/lib/redmine/wiki_formatting/textile/html_parser.rb b/lib/redmine/wiki_formatting/textile/html_parser.rb index 201e69c..fba6b1d 100644 --- a/lib/redmine/wiki_formatting/textile/html_parser.rb +++ b/lib/redmine/wiki_formatting/textile/html_parser.rb @@ -33,7 +33,8 @@ module Redmine 'h3' => {:pre => "\n\nh3. ", :post => "\n\n"}, 'h4' => {:pre => "\n\nh4. ", :post => "\n\n"}, 'h5' => {:pre => "\n\nh5. ", :post => "\n\n"}, - 'h6' => {:pre => "\n\nh6. ", :post => "\n\n"} + 'h6' => {:pre => "\n\nh6. ", :post => "\n\n"}, + 'style' => '' } end end 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 4662aea..8f6ff5a 100644 --- a/test/unit/lib/redmine/wiki_formatting/html_parser_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/html_parser_test.rb @@ -27,4 +27,9 @@ class Redmine::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase assert_equal "A html snippet with\na new line.", @parser.to_text('

A html snippet with
a new line.

') end + + def test_should_remove_style_tags_from_body + assert_equal "Text", + @parser.to_text('Text') + end end