Permalink
Browse files

Improved auto_link to match more valid urls correctly

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5704 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 90179a9 commit 2f9d44e50beb7c51fd26bf900c4d18986c9ab754 Tobias Lütke committed Dec 7, 2006
View
@@ -1,13 +1,15 @@
*SVN*
+* Improved auto_link to match more valid urls correctly [Tobias Luetke]
+
* Add singleton resources. [Rick Olson]
map.resource :account
GET /account
GET /account;edit
UPDATE /account
- DELEE /account
+ DELETE /account
* respond_to recognizes JSON. render :json => @person.to_json automatically sets the content type and takes a :callback option to specify a client-side function to call using the rendered JSON as an argument. #4185 [Scott Raymond, eventualbuddha]
# application/json response with body 'Element.show({:name: "David"})'
@@ -356,24 +356,24 @@ def set_cycle(name, cycle_object)
end
AUTO_LINK_RE = %r{
- ( # leading text
- <\w+.*?>| # leading HTML tag, or
- [^=!:'"/]| # leading punctuation, or
- ^ # beginning of line
+ ( # leading text
+ <\w+.*?>| # leading HTML tag, or
+ [^=!:'"/]| # leading punctuation, or
+ ^ # beginning of line
)
(
- (?:https?://)| # protocol spec, or
- (?:www\.) # www.*
+ (?:https?://)| # protocol spec, or
+ (?:www\.) # www.*
)
(
- [-\w]+ # subdomain or domain
- (?:\.[-\w]+)* # remaining subdomains or domain
- (?::\d+)? # port
- (?:/(?:[~\w%.;-]+)?)* # path
- (?:\?[\w%&=.;-]+)? # query string
- (?:\#\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
+ ([[:punct:]]|\s|<|$) # trailing text
}x unless const_defined?(:AUTO_LINK_RE)
# Turns all urls into clickable links. If a block is given, each url
@@ -152,6 +152,10 @@ def test_auto_linking
link4_result = %{<a href="#{link4_raw}">#{link4_raw}</a>}
link5_raw = 'http://foo.example.com:3000/controller/action'
link5_result = %{<a href="#{link5_raw}">#{link5_raw}</a>}
+ link6_raw = 'http://foo.example.com:3000/controller/action+pack'
+ link6_result = %{<a href="#{link6_raw}">#{link6_raw}</a>}
+ link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
+ link7_result = %{<a href="#{link7_raw}">#{link7_raw}</a>}
assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses)
assert_equal %(Go to #{link_result}), auto_link("Go to #{link_raw}", :urls)
@@ -177,6 +181,8 @@ def test_auto_linking
assert_equal %(<p>Link #{link4_result}</p>), auto_link("<p>Link #{link4_raw}</p>")
assert_equal %(<p>#{link4_result} Link</p>), auto_link("<p>#{link4_raw} Link</p>")
assert_equal %(<p>#{link5_result} Link</p>), auto_link("<p>#{link5_raw} Link</p>")
+ assert_equal %(<p>#{link6_result} Link</p>), auto_link("<p>#{link6_raw} Link</p>")
+ assert_equal %(<p>#{link7_result} Link</p>), auto_link("<p>#{link7_raw} Link</p>")
assert_equal '', auto_link(nil)
assert_equal '', auto_link('')
end

0 comments on commit 2f9d44e

Please sign in to comment.