Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hold onto trailing = and & characters as part of urls #45

Merged
merged 4 commits into from

3 participants

@tardate
Collaborator

Fixes situation with urls that have trailing = or & characters - ensures that these are kept as part of the url after auto_link.

NB: I've submitted this commit is on top of pull request #44 (so that I could run the tests)

ktdreyer and others added some commits
@ktdreyer ktdreyer require timeout in tests
When running "testrb test/test_rails_autolink.rb", the test suite fails:

  NameError: uninitialized constant TestRailsAutolink::Timeout

Explicitly load the timeout gem during the tests to fix this error.
da6ff3c
@tardate tardate refactor Gemfile/tests to revive ability to run against Rails 3.2.x, …
…4.0.x, 4.1.x

* simplify required modules for tests to avoid version-specific breakage because of internal Rails refactoring
* Gemfile has notes on dependencies - it's not automatic
* mintiest pegged down for Rails 3.2.x to avoid assert_dom_equal issue
* if rails_autolink/helpers included before action_view/helpers, it was obscuring helper methods
6244a80
@tardate tardate make test_auto_link_email_addres_with_especial_chars work on Rails 3.x
 
* original from pull request #31
5e25346
@tardate tardate hold onto trailing = and & as part of urls 8589904
@tardate
Collaborator

any comments on this? I'd like to get this merged onto mainline and into a released version of the gem if possible.

@tenderlove
Owner

@tardate congratulations! You are now a rails_autolink-core team member. Please merge this PR yourself. Also send me your email address and I'll give you release access on rubygems.org.

@tardate
Collaborator

@tenderlove ha! I got more than I bargained for!

Thanks for this, happy to help.

@tardate tardate merged commit 8589904 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 7, 2013
  1. @ktdreyer

    require timeout in tests

    ktdreyer authored
    When running "testrb test/test_rails_autolink.rb", the test suite fails:
    
      NameError: uninitialized constant TestRailsAutolink::Timeout
    
    Explicitly load the timeout gem during the tests to fix this error.
Commits on Apr 17, 2014
  1. @tardate

    refactor Gemfile/tests to revive ability to run against Rails 3.2.x, …

    tardate authored
    …4.0.x, 4.1.x
    
    * simplify required modules for tests to avoid version-specific breakage because of internal Rails refactoring
    * Gemfile has notes on dependencies - it's not automatic
    * mintiest pegged down for Rails 3.2.x to avoid assert_dom_equal issue
    * if rails_autolink/helpers included before action_view/helpers, it was obscuring helper methods
  2. @tardate

    make test_auto_link_email_addres_with_especial_chars work on Rails 3.x

    tardate authored
     
    * original from pull request #31
  3. @tardate
This page is out of date. Refresh to see the latest.
View
11 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'
View
2  lib/rails_autolink/helpers.rb
@@ -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
View
33 test/test_rails_autolink.rb
@@ -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
@@ -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'
@@ -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@...................................
Something went wrong with that request. Please try again.