From da7ba91d8666770c6288f8d25cd501fd227b0413 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 11 Sep 2005 05:53:52 +0000 Subject: Fixed that TextHelper#auto_link_urls would include punctuation in the links #2166, #1671 [eigentone] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2183 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/text_helper.rb | 4 ++-- actionpack/test/template/text_helper_test.rb | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index e38c743506..1b8c9b3c2f 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that TextHelper#auto_link_urls would include punctuation in the links #2166, #1671 [eigentone] + * Fixed that number_to_currency(1000, {:precision => 0})) should return "$1,000", instead of "$1,000." #2122 [sd@notso.net] * Allow link_to_remote to use any DOM-element as the parent of the form elements to be submitted #2137 [erik@ruby-lang.nl]. Example: diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index e8b7d7810a..217cf6c9f8 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -199,8 +199,8 @@ module ActionView # Turns all urls into clickable links. def auto_link_urls(text, href_options = {}) - text.gsub(/(<\w+.*?>|[^=!:'"\/]|^)((?:http[s]?:\/\/)|(?:www\.))([^\s<]+\/?)([[:punct:]]|\s|<|$)/) do - all, a, b, c, d = $&, $1, $2, $3, $4 + text.gsub(/(<\w+.*?>|[^=!:'"\/]|^)((?:http[s]?:\/\/)|(?:www\.))(([\w]+[[:punct:]]?)*\w+[\/]?)([[:punct:]]|\s|<|$)/) do + all, a, b, c, d = $&, $1, $2, $3, $5 if a =~ /#{link_raw}} link2_raw = 'www.rubyonrails.com' link2_result = %{#{link2_raw}} + link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281' + link3_result = %{#{link3_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) @@ -92,11 +96,21 @@ class TextHelperTest < Test::Unit::TestCase assert_equal %(Go to #{link_result} and say hello to #{email_result}), auto_link("Go to #{link_raw} and say hello to #{email_raw}") assert_equal %(

Link #{link_result}

), auto_link("

Link #{link_raw}

") assert_equal %(

#{link_result} Link

), auto_link("

#{link_raw} Link

") + assert_equal %(

Link #{link_result_with_options}

), auto_link("

Link #{link_raw}

", :all, {:target => "_blank"}) + assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.)) + assert_equal %(

Go to #{link_result}, then say hello to #{email_result}.

), auto_link(%(

Go to #{link_raw}, then say hello to #{email_raw}.

)) assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls) assert_equal %(Go to #{link2_raw}), auto_link("Go to #{link2_raw}", :email_addresses) assert_equal %(

Link #{link2_result}

), auto_link("

Link #{link2_raw}

") assert_equal %(

#{link2_result} Link

), auto_link("

#{link2_raw} Link

") - assert_equal %(

Link #{link_result_with_options}

), auto_link("

Link #{link_raw}

", :all, {:target => "_blank"}) + assert_equal %(Go to #{link2_result}.), auto_link(%(Go to #{link2_raw}.)) + assert_equal %(

Say hello to #{email_result}, then go to #{link2_result}.

), auto_link(%(

Say hello to #{email_raw}, then go to #{link2_raw}.

)) + assert_equal %(Go to #{link3_result}), auto_link("Go to #{link3_raw}", :urls) + assert_equal %(Go to #{link3_raw}), auto_link("Go to #{link3_raw}", :email_addresses) + assert_equal %(

Link #{link3_result}

), auto_link("

Link #{link3_raw}

") + assert_equal %(

#{link3_result} Link

), auto_link("

#{link3_raw} Link

") + assert_equal %(Go to #{link3_result}.), auto_link(%(Go to #{link3_raw}.)) + assert_equal %(

Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.

), auto_link(%(

Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.

)) end def test_sanitize_form -- cgit v1.2.3