]> source.dussan.org Git - redmine.git/commitdiff
Fix that receiving HTML email fails if it contains a link without an href attribute...
authorGo MAEDA <maeda@farend.jp>
Sat, 9 Nov 2019 06:06:05 +0000 (06:06 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 9 Nov 2019 06:06:05 +0000 (06:06 +0000)
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
lib/redmine/wiki_formatting/textile/html_parser.rb
test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb
test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb

index ff25a0bd21626aa5ae900cad05a3d4bc0a0daa29..636a3443e2542d361278e5e0db35723383aae877 100644 (file)
@@ -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
index 8623c206894cb6e12cc9e1e6302f525d9f1b403a..27dc5f9756c2ffc4f43c85ec07d6047629f5fe74 100644 (file)
@@ -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
index 45a5a52f9949a640026fab9b9c8cf6ce1ebc720b..55ca3f9c1425554229f0ae9c4ba1d7659c308cc9 100644 (file)
@@ -31,8 +31,15 @@ class Redmine::WikiFormatting::MarkdownHtmlParserTest < ActiveSupport::TestCase
 
     assert_equal 'foo [bar](http://example.com/) baz',
       @parser.to_text('foo<a href="http://example.com/">bar</a>baz')
+
     assert_equal 'foo http://example.com/ baz',
       @parser.to_text('foo<a href="http://example.com/"></a>baz')
+
+    assert_equal 'foobarbaz',
+      @parser.to_text('foo<a name="Header-one">bar</a>baz')
+
+    assert_equal 'foobaz',
+      @parser.to_text('foo<a name="Header-one"/>baz')
   end
 
   def test_html_tables_conversion
index 86d7e66d291f628d51e9e1534d930d0766ac0e37..17221989d4694356e8bc143f6c706af43a2274fa 100644 (file)
@@ -31,8 +31,15 @@ class Redmine::WikiFormatting::TextileHtmlParserTest < ActiveSupport::TestCase
 
     assert_equal 'foo "bar":http://example.com/ baz',
       @parser.to_text('foo<a href="http://example.com/">bar</a>baz')
+
     assert_equal 'foo http://example.com/ baz',
       @parser.to_text('foo<a href="http://example.com/"></a>baz')
+
+    assert_equal 'foobarbaz',
+      @parser.to_text('foo<a name="Header-one">bar</a>baz')
+
+    assert_equal 'foobaz',
+      @parser.to_text('foo<a name="Header-one"/>baz')
   end
 
   def test_html_tables_conversion