diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index a72715e0e5e7c8d186e707623f4a0e270081cb51..d9ba19526b23d5b9053d6c1a9d8ed050a8131797 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Improved auto_link to match more valid urls correctly [Tobias Luetke] + * Add singleton resources. [Rick Olson] map.resource :account @@ -7,7 +9,7 @@ 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"})' diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 0b1b46b0f300fa0984093afb20f880223db4976b..c921fcae4b6935c79964923b23e957992de4e6c3 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -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 diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index bf008ae9df08fd004668254e1e4afacbd3f178a4..37eff78e76bb128ba5e4dbb558b8d1b82f3f00d4 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -152,6 +152,10 @@ def test_auto_linking link4_result = %{#{link4_raw}} link5_raw = 'http://foo.example.com:3000/controller/action' link5_result = %{#{link5_raw}} + link6_raw = 'http://foo.example.com:3000/controller/action+pack' + link6_result = %{#{link6_raw}} + link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123' + link7_result = %{#{link7_raw}} 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 %(

Link #{link4_result}

), auto_link("

Link #{link4_raw}

") assert_equal %(

#{link4_result} Link

), auto_link("

#{link4_raw} Link

") assert_equal %(

#{link5_result} Link

), auto_link("

#{link5_raw} Link

") + assert_equal %(

#{link6_result} Link

), auto_link("

#{link6_raw} Link

") + assert_equal %(

#{link7_result} Link

), auto_link("

#{link7_raw} Link

") assert_equal '', auto_link(nil) assert_equal '', auto_link('') end