From fc2e4c1eba584205805a80dc4d7bb25d949a6840 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 9 Nov 2019 06:06:05 +0000 Subject: [PATCH] Fix that receiving HTML email fails if it contains a link without an href attribute (#31695). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@18988 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/wiki_formatting/markdown/html_parser.rb | 10 +++++++++- lib/redmine/wiki_formatting/textile/html_parser.rb | 10 +++++++++- .../wiki_formatting/markdown_html_parser_test.rb | 7 +++++++ .../wiki_formatting/textile_html_parser_test.rb | 7 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/redmine/wiki_formatting/markdown/html_parser.rb b/lib/redmine/wiki_formatting/markdown/html_parser.rb index ff25a0bd2..636a3443e 100644 --- a/lib/redmine/wiki_formatting/markdown/html_parser.rb +++ b/lib/redmine/wiki_formatting/markdown/html_parser.rb @@ -37,7 +37,15 @@ module Redmine 'h6' => {:pre => "\n\n###### ", :post => "\n\n"}, 'th' => {:pre => '*', :post => "*\n"}, 'td' => {:pre => '', :post => "\n"}, - 'a' => lambda {|node| node.content.present? ? %| [#{node.content}](#{node.attributes['href'].value}) | : %| #{node.attributes['href'].value} |} + 'a' => lambda do |node| + if node.content.present? && node.attributes.key?('href') + %| [#{node.content}](#{node.attributes['href'].value}) | + elsif node.attributes.key?('href') + %| #{node.attributes['href'].value} | + else + node.content + end + end ) end end diff --git a/lib/redmine/wiki_formatting/textile/html_parser.rb b/lib/redmine/wiki_formatting/textile/html_parser.rb index 8623c2068..27dc5f975 100644 --- a/lib/redmine/wiki_formatting/textile/html_parser.rb +++ b/lib/redmine/wiki_formatting/textile/html_parser.rb @@ -37,7 +37,15 @@ module Redmine 'h6' => {:pre => "\n\nh6. ", :post => "\n\n"}, 'th' => {:pre => '*', :post => "*\n"}, 'td' => {:pre => '', :post => "\n"}, - 'a' => lambda {|node| node.content.present? ? %| "#{node.content}":#{node.attributes['href'].value} | : %| #{node.attributes['href'].value} |} + 'a' => lambda do |node| + if node.content.present? && node.attributes.key?('href') + %| "#{node.content}":#{node.attributes['href'].value} | + elsif node.attributes.key?('href') + %| #{node.attributes['href'].value} | + else + node.content + end + end ) end end diff --git a/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb b/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb index 45a5a52f9..55ca3f9c1 100644 --- a/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb @@ -31,8 +31,15 @@ class Redmine::WikiFormatting::MarkdownHtmlParserTest < ActiveSupport::TestCase assert_equal 'foo [bar](http://example.com/) baz', @parser.to_text('foobarbaz') + assert_equal 'foo http://example.com/ baz', @parser.to_text('foobaz') + + assert_equal 'foobarbaz', + @parser.to_text('foobarbaz') + + assert_equal 'foobaz', + @parser.to_text('foobaz') end def test_html_tables_conversion diff --git a/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb b/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb index 86d7e66d2..17221989d 100644 --- a/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb @@ -31,8 +31,15 @@ class Redmine::WikiFormatting::TextileHtmlParserTest < ActiveSupport::TestCase assert_equal 'foo "bar":http://example.com/ baz', @parser.to_text('foobarbaz') + assert_equal 'foo http://example.com/ baz', @parser.to_text('foobaz') + + assert_equal 'foobarbaz', + @parser.to_text('foobarbaz') + + assert_equal 'foobaz', + @parser.to_text('foobaz') end def test_html_tables_conversion