diff options
author | Jamis Buck <jamis@37signals.com> | 2005-09-13 18:48:34 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-09-13 18:48:34 +0000 |
commit | b97f4e459707694bd98babb7a8890f08016d5ebf (patch) | |
tree | 286d90c2f694a9e4b21dd5e0c5b06a08b92d6c90 /actionpack/lib | |
parent | 0f8a3a31a7a673837e414d363aa166dfc66809a9 (diff) | |
download | rails-b97f4e459707694bd98babb7a8890f08016d5ebf.tar.gz rails-b97f4e459707694bd98babb7a8890f08016d5ebf.tar.bz2 rails-b97f4e459707694bd98babb7a8890f08016d5ebf.zip |
Fix autolinking to not include trailing tags as part of the URL
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2237 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 413f32532d..7b883a8b27 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -279,9 +279,27 @@ module ActionView text.gsub(/([\\|?+*\/\)\(])/) { |m| "\\#{$1}" } end + AUTO_LINK_RE = / + ( # leading text + <\w+.*?>| # leading HTML tag, or + [^=!:'"\/]| # leading punctuation, or + ^ # beginning of line + ) + ( + (?:http[s]?:\/\/)| # protocol spec, or + (?:www\.) # www.* + ) + ( + ([\w]+[\/.-]?)* # url segment + \w+[\/]? # url tail + (?:\#\w*)? # trailing anchor + ) + ([[:punct:]]|\s|<|$) # trailing text + /x + # Turns all urls into clickable links. def auto_link_urls(text, href_options = {}) - text.gsub(/(<\w+.*?>|[^=!:'"\/]|^)((?:http[s]?:\/\/)|(?:www\.))(([\w]+[[:punct:]]?)*\w+[\/]?)([[:punct:]]|\s|<|$)/) do + text.gsub(AUTO_LINK_RE) do all, a, b, c, d = $&, $1, $2, $3, $5 if a =~ /<a\s/i # don't replace URL's that are already linked all |