aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/text_helper.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-09-02 01:47:32 +0000
committerJamis Buck <jamis@37signals.com>2006-09-02 01:47:32 +0000
commitbdf91d67484bd836dc34d54b5565ea05dbb37f20 (patch)
treed23d4f6a6fd5a1479168f3a0edda2c55ec84ab51 /actionpack/lib/action_view/helpers/text_helper.rb
parente4a4287c971f6e61f59815988f5fc69176cb14de (diff)
downloadrails-bdf91d67484bd836dc34d54b5565ea05dbb37f20.tar.gz
rails-bdf91d67484bd836dc34d54b5565ea05dbb37f20.tar.bz2
rails-bdf91d67484bd836dc34d54b5565ea05dbb37f20.zip
Make auto_link parse a greater subset of valid url formats.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4896 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/text_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb29
1 files changed, 16 insertions, 13 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index f668f09d34..a2efedf100 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -313,23 +313,26 @@ module ActionView
@_cycles[name] = cycle_object
end
- AUTO_LINK_RE = /
- ( # leading text
- <\w+.*?>| # leading HTML tag, or
- [^=!:'"\/]| # leading punctuation, or
- ^ # beginning of line
+ AUTO_LINK_RE = %r{
+ ( # leading text
+ <\w+.*?>| # leading HTML tag, or
+ [^=!:'"/]| # leading punctuation, or
+ ^ # beginning of line
)
(
- (?:http[s]?:\/\/)| # protocol spec, or
- (?:www\.) # www.*
+ (?:https?://)| # protocol spec, or
+ (?:www\.) # www.*
)
(
- ([\w]+:?[=?&\/.-]?)* # url segment
- \w+[\/]? # url tail
- (?:\#\w*)? # trailing anchor
+ [-\w]+ # subdomain or domain
+ (?:\.[-\w]+)* # remaining subdomains or domain
+ (?::\d+)? # port
+ (?:/(?:[~\w%.;-]+)?)* # path
+ (?:\?[\w%&=.;-]+)? # query string
+ (?:\#\w*)? # trailing anchor
)
- ([[:punct:]]|\s|<|$) # trailing text
- /x unless const_defined?(:AUTO_LINK_RE)
+ ([[:punct:]]|\s|<|$) # trailing text
+ }x unless const_defined?(:AUTO_LINK_RE)
# Turns all urls into clickable links. If a block is given, each url
# is yielded and the result is used as the link text. Example:
@@ -339,7 +342,7 @@ module ActionView
def auto_link_urls(text, href_options = {})
extra_options = tag_options(href_options.stringify_keys) || ""
text.gsub(AUTO_LINK_RE) do
- all, a, b, c, d = $&, $1, $2, $3, $5
+ all, a, b, c, d = $&, $1, $2, $3, $4
if a =~ /<a\s/i # don't replace URL's that are already linked
all
else