diff --git a/lib/redcloth3.rb b/lib/redcloth3.rb index 045d44f5..fa48b2db 100644 --- a/lib/redcloth3.rb +++ b/lib/redcloth3.rb @@ -825,7 +825,7 @@ class RedCloth3 < String post = ")"+post # add closing parenth to post end atts = pba( atts ) - atts = " href=\"#{ url }#{ slash }\"#{ atts }" + atts = " href=\"#{ htmlesc url }#{ slash }\"#{ atts }" atts << " title=\"#{ htmlesc title }\"" if title atts = shelve( atts ) if atts diff --git a/lib/redmine/wiki_formatting/textile/formatter.rb b/lib/redmine/wiki_formatting/textile/formatter.rb index e0cdd6aa..7645e020 100644 --- a/lib/redmine/wiki_formatting/textile/formatter.rb +++ b/lib/redmine/wiki_formatting/textile/formatter.rb @@ -21,6 +21,7 @@ module Redmine module WikiFormatting module Textile class Formatter < RedCloth3 + include ActionView::Helpers::TagHelper # auto_link rule after textile rules so that it doesn't break !image_url! tags RULES = [:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto, :inline_toc] @@ -134,7 +135,8 @@ module Redmine url=url[0..-2] # discard closing parenth from url post = ")"+post # add closing parenth to post end - %(#{leading}#{proto + url}#{post}) + tag = content_tag('a', proto + url, :href => "#{proto=="www."?"http://www.":proto}#{url}", :class => 'external') + %(#{leading}#{tag}#{post}) end end end @@ -146,7 +148,7 @@ module Redmine if text.match(/]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/) mail else - %{#{mail}} + content_tag('a', mail, :href => "mailto:#{mail}", :class => "email") end end end diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 656d05f8..180093be 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -60,12 +60,14 @@ class ApplicationHelperTest < HelperTestCase 'sftp://foo.bar' => 'sftp://foo.bar', # two exclamation marks 'http://example.net/path!602815048C7B5C20!302.html' => 'http://example.net/path!602815048C7B5C20!302.html', + # escaping + 'http://foo"bar' => 'http://foo"bar', } to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } end def test_auto_mailto - assert_equal '

', + assert_equal '

', textilizable('test@foo.bar') end @@ -130,6 +132,8 @@ RAW "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "system administrator", # two exclamation marks '"a link":http://example.net/path!602815048C7B5C20!302.html' => 'a link', + # escaping + '"test":http://foo"bar' => 'test', } to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } end