Skip to content

Commit

Permalink
Merge remote-tracking branch 'evendis/hold_onto_trailing_cruft'
Browse files Browse the repository at this point in the history
  • Loading branch information
tardate committed Jun 8, 2014
2 parents a4d3188 + 8589904 commit 3bcdfe7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
11 changes: 9 additions & 2 deletions Gemfile
@@ -1,6 +1,13 @@
source 'https://rubygems.org'

# To test on latest Rails release, use the following:
gem 'rails'
gem 'arel'
gem 'rack'
gem 'minitest'

# To test on Rails 4.0.x release, use the following e.g. for 4.0.1:
# gem 'rails', '= 4.0.1'
# gem 'minitest'

# To test on Rails 3.2.x, use the following e.g. for 3.2.17:
# gem 'rails', '= 3.2.17'
# gem 'minitest', '= 4.2'
2 changes: 1 addition & 1 deletion lib/rails_autolink/helpers.rb
Expand Up @@ -98,7 +98,7 @@ def auto_link_urls(text, html_options = {}, options = {})
href
else
# don't include trailing punctuation character as part of the URL
while href.sub!(/[^#{WORD_PATTERN}\/-]$/, '')
while href.sub!(/[^#{WORD_PATTERN}\/-=&]$/, '')
punctuation.push $&
if opening = BRACKETS[punctuation.last] and href.scan(opening).size > href.scan(punctuation.last).size
href << punctuation.pop
Expand Down
33 changes: 22 additions & 11 deletions test/test_rails_autolink.rb
Expand Up @@ -2,20 +2,16 @@

require "minitest/autorun"
require "rails"
require "rails_autolink/helpers"
require 'erb'
require 'cgi'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support'
require 'active_support/core_ext'
require 'action_pack'
require 'action_view/helpers/capture_helper'
require 'action_view/helpers/sanitize_helper'
require 'action_view/helpers/url_helper'
require 'action_view/helpers/tag_helper'
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/encoding'
require 'action_view'
require 'action_view/helpers'
require 'action_dispatch/testing/assertions'
require 'action_view/helpers/text_helper'
require 'action_view/helpers/output_safety_helper'
require 'timeout'
require "rails_autolink/helpers"

class TestRailsAutolink < MiniTest::Unit::TestCase
include ActionView::Helpers::CaptureHelper
Expand Down Expand Up @@ -174,7 +170,12 @@ def test_auto_link_email_address

def test_auto_link_email_addres_with_especial_chars
email_raw = "and&re$la*+r-a.o'rea=l~ly@tenderlovemaking.com"
email_sanitized = "and&amp;re$la*+r-a.o&#39;rea=l~ly@tenderlovemaking.com"
email_sanitized = if Rails.version =~ /^3/
# mail_to changed the number base it rendered HTML encoded characters at some point
"and&amp;re$la*+r-a.o&#x27;rea=l~ly@tenderlovemaking.com"
else
"and&amp;re$la*+r-a.o&#39;rea=l~ly@tenderlovemaking.com"
end
email_result = %{<a href="mailto:#{email_raw}">#{email_sanitized}</a>}
assert_equal email_result, auto_link(email_raw)
assert !auto_link_email_addresses(email_result).html_safe?, 'should not be html safe'
Expand Down Expand Up @@ -311,6 +312,16 @@ def test_auto_link_parsing
end
end

def test_autolink_with_trailing_equals_on_link
url = "http://www.rubyonrails.com/foo.cgi?trailing_equals="
assert_equal generate_result(url), auto_link(url)
end

def test_autolink_with_trailing_amp_on_link
url = "http://www.rubyonrails.com/foo.cgi?trailing_ampersand=value&"
assert_equal generate_result(url), auto_link(url)
end

def test_auto_link_does_not_timeout_when_parsing_odd_email_input
inputs = %w(
foo@...................................
Expand Down

0 comments on commit 3bcdfe7

Please sign in to comment.