mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure auto_link does not ignore multiple trailing punctuations [#2504 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
53dda29f8b
commit
11bac70078
2 changed files with 14 additions and 6 deletions
|
@ -535,7 +535,7 @@ module ActionView
|
|||
link_attributes = html_options.stringify_keys
|
||||
text.gsub(AUTO_LINK_RE) do
|
||||
href = $&
|
||||
punctuation = ''
|
||||
punctuation = []
|
||||
left, right = $`, $'
|
||||
# detect already linked URLs and URLs in the middle of a tag
|
||||
if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
|
||||
|
@ -543,17 +543,18 @@ module ActionView
|
|||
href
|
||||
else
|
||||
# don't include trailing punctuation character as part of the URL
|
||||
if href.sub!(/[^\w\/-]$/, '') and punctuation = $& and opening = BRACKETS[punctuation]
|
||||
if href.scan(opening).size > href.scan(punctuation).size
|
||||
href << punctuation
|
||||
punctuation = ''
|
||||
while href.sub!(/[^\w\/-]$/, '')
|
||||
punctuation.push $&
|
||||
if opening = BRACKETS[punctuation.last] and href.scan(opening).size > href.scan(punctuation.last).size
|
||||
href << punctuation.pop
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
link_text = block_given?? yield(href) : href
|
||||
href = 'http://' + href unless href.index('http') == 0
|
||||
|
||||
content_tag(:a, h(link_text), link_attributes.merge('href' => href)) + punctuation
|
||||
content_tag(:a, h(link_text), link_attributes.merge('href' => href)) + punctuation.reverse.join('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -401,6 +401,13 @@ class TextHelperTest < ActionView::TestCase
|
|||
auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
|
||||
:link => :all, :html => { :class => "menu", :target => "_blank" })
|
||||
end
|
||||
|
||||
def test_auto_link_with_multiple_trailing_punctuations
|
||||
url = "http://youtube.com"
|
||||
url_result = generate_result(url)
|
||||
assert_equal url_result, auto_link(url)
|
||||
assert_equal "(link: #{url_result}).", auto_link("(link: #{url}).")
|
||||
end
|
||||
|
||||
def test_cycle_class
|
||||
value = Cycle.new("one", 2, "3")
|
||||
|
|
Loading…
Reference in a new issue