mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
04594cfadb
commit
da7ba91d86
3 changed files with 19 additions and 3 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue