aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb4
-rw-r--r--actionpack/test/template/text_helper_test.rb16
3 files changed, 19 insertions, 3 deletions
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 =~ /<a\s/i # don't replace URL's that are already linked
all
else
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 2206ac7d04..9b704711e1 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -1,6 +1,8 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/numeric' # for human_size
+require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' # for stringify_keys
+require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/object_and_class.rb' # for blank?
class TextHelperTest < Test::Unit::TestCase
include ActionView::Helpers::TextHelper
@@ -85,6 +87,8 @@ class TextHelperTest < Test::Unit::TestCase
link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
link2_raw = 'www.rubyonrails.com'
link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
+ link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
+ link3_result = %{<a href="#{link3_raw}">#{link3_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)
@@ -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 %(<p>Link #{link_result}</p>), auto_link("<p>Link #{link_raw}</p>")
assert_equal %(<p>#{link_result} Link</p>), auto_link("<p>#{link_raw} Link</p>")
+ assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
+ assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.))
+ assert_equal %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), auto_link(%(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>))
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 %(<p>Link #{link2_result}</p>), auto_link("<p>Link #{link2_raw}</p>")
assert_equal %(<p>#{link2_result} Link</p>), auto_link("<p>#{link2_raw} Link</p>")
- assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
+ assert_equal %(Go to #{link2_result}.), auto_link(%(Go to #{link2_raw}.))
+ assert_equal %(<p>Say hello to #{email_result}, then go to #{link2_result}.</p>), auto_link(%(<p>Say hello to #{email_raw}, then go to #{link2_raw}.</p>))
+ 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 %(<p>Link #{link3_result}</p>), auto_link("<p>Link #{link3_raw}</p>")
+ assert_equal %(<p>#{link3_result} Link</p>), auto_link("<p>#{link3_raw} Link</p>")
+ assert_equal %(Go to #{link3_result}.), auto_link(%(Go to #{link3_raw}.))
+ assert_equal %(<p>Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
end
def test_sanitize_form