diff options
author | Mislav Marohnić <mislav.marohnic@gmail.com> | 2010-04-17 05:13:40 +0200 |
---|---|---|
committer | Mislav Marohnić <mislav.marohnic@gmail.com> | 2010-05-24 11:25:24 +0200 |
commit | 133ada6ab0f0cb7bef2bd40dbc18f2d5bc6b964e (patch) | |
tree | 06bb2e121beabbc72f377f39848c164c32c592fb /actionpack/lib/action_view/helpers | |
parent | 69a9669d9d51fae8f591cd7a0108b6fc4b47070c (diff) | |
download | rails-133ada6ab0f0cb7bef2bd40dbc18f2d5bc6b964e.tar.gz rails-133ada6ab0f0cb7bef2bd40dbc18f2d5bc6b964e.tar.bz2 rails-133ada6ab0f0cb7bef2bd40dbc18f2d5bc6b964e.zip |
auto_link: support arbitrary URI schemes like "ftp:" and "file:"
recognizes all URI scheme allowed characters, such as colon and period.
[#3494 state:resolved]
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 0e1bc139ff..fa930ac626 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -537,7 +537,7 @@ module ActionView end AUTO_LINK_RE = %r{ - ( https?:// | www\. ) + (?: ([\w+.:-]+:)// | www\. ) [^\s<]+ }x unless const_defined?(:AUTO_LINK_RE) @@ -548,7 +548,7 @@ module ActionView def auto_link_urls(text, html_options = {}) link_attributes = html_options.stringify_keys text.gsub(AUTO_LINK_RE) do - href = $& + scheme, href = $1, $& punctuation = [] left, right = $`, $' # detect already linked URLs and URLs in the middle of a tag @@ -566,7 +566,7 @@ module ActionView end link_text = block_given?? yield(href) : href - href = 'http://' + href unless href =~ %r{^[a-z]+://}i + href = 'http://' + href unless scheme content_tag(:a, h(link_text), link_attributes.merge('href' => href)) + punctuation.reverse.join('') end |