rails_autolink 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 91c4563b853f02631b7bf2d4b4cc26fed12c6e02
4
- data.tar.gz: 6e4207505ba1093565b223b36fe7ca1c35020acc
2
+ SHA256:
3
+ metadata.gz: 8151243f8627232813288a4ec8e6e7c9ff2df1b9bab1d8d093534fc09359a866
4
+ data.tar.gz: 6ee3e115c0e7400fc0f1aebd68ef5e727db8b0d08b46c3daff87788d5ff7f52a
5
5
  SHA512:
6
- metadata.gz: be27ad19fd951b6631eba721eb250ce6cd32dde1c819ff4834c2ccb9bd676c708d099e6ca9fe5dbf878bf4b70095713a0fa3577c6a8f82d8f0ef8cdddce8fea7
7
- data.tar.gz: fa33c890166fc907cbc4d54ec6aeda58c60b7850dcb80c8684b79c77e72042e2ea685338ef6882dea0c4b801dde29bec1559880e4f34f86c1b02059fc5d3fab2
6
+ metadata.gz: 98f03447600e361b2061cb12ccab3e215d56eff9e3ffacf9a70507873fea8e3a92882446959d307f787206aed77f8d5f28a248c3dbcea56e274335592ae04028
7
+ data.tar.gz: 10228d699f37f4a8d08e7d430e3eb9516387ced3b3dc964e95b1a4717deda33121a0670ee4b6cccb042f08ff0b53a7f783c50a63b73de0a0c592fe6f81144ab2
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.1.7 / 2022-11-02
2
+
3
+ * Require a word part after “www.” when auto linking #75
4
+ * Include trailing hyphens in URL #74
5
+ * Make test suite work under Rails 7 #72
6
+ * Optimize email address parsing #63
7
+ * Switch to MiniTest 5 #48
8
+
1
9
  === 1.1.6 / 2014-06-08
2
10
 
3
11
  * Fixed a potential XSS vulnerability #47
@@ -71,7 +71,7 @@ module RailsAutolink
71
71
  private
72
72
 
73
73
  AUTO_LINK_RE = %r{
74
- (?: ((?:ed2k|ftp|http|https|irc|mailto|news|gopher|nntp|telnet|webcal|xmpp|callto|feed|svn|urn|aim|rsync|tag|ssh|sftp|rtsp|afs|file):)// | www\. )
74
+ (?: ((?:ed2k|ftp|http|https|irc|mailto|news|gopher|nntp|telnet|webcal|xmpp|callto|feed|svn|urn|aim|rsync|tag|ssh|sftp|rtsp|afs|file):)// | www\.\w )
75
75
  [^\s<\u00A0"]+
76
76
  }ix
77
77
 
@@ -79,7 +79,7 @@ module RailsAutolink
79
79
  AUTO_LINK_CRE = [/<[^>]+$/, /^[^>]*>/, /<a\b.*?>/i, /<\/a>/i]
80
80
 
81
81
  AUTO_EMAIL_LOCAL_RE = /[\w.!#\$%&'*\/=?^`{|}~+-]/
82
- AUTO_EMAIL_RE = /[\w.!#\$%+-]\.?#{AUTO_EMAIL_LOCAL_RE}*@[\w-]+(?:\.[\w-]+)+/
82
+ AUTO_EMAIL_RE = /(?<!#{AUTO_EMAIL_LOCAL_RE})[\w.!#\$%+-]\.?#{AUTO_EMAIL_LOCAL_RE}*@[\w-]+(?:\.[\w-]+)+/
83
83
 
84
84
  BRACKETS = { ']' => '[', ')' => '(', '}' => '{' }
85
85
 
@@ -98,7 +98,7 @@ module RailsAutolink
98
98
  href
99
99
  else
100
100
  # don't include trailing punctuation character as part of the URL
101
- while href.sub!(/[^#{WORD_PATTERN}\/-=&]$/, '')
101
+ while href.sub!(/[^#{WORD_PATTERN}\/\-=;]$/, '')
102
102
  punctuation.push $&
103
103
  if opening = BRACKETS[punctuation.last] and href.scan(opening).size > href.scan(punctuation.last).size
104
104
  href << punctuation.pop
@@ -1,3 +1,3 @@
1
1
  module RailsAutolink
2
- VERSION = '1.1.6'
3
- end
2
+ VERSION = '1.1.7'
3
+ end
@@ -13,7 +13,7 @@ require 'action_dispatch/testing/assertions'
13
13
  require 'timeout'
14
14
  require "rails_autolink/helpers"
15
15
 
16
- class TestRailsAutolink < MiniTest::Unit::TestCase
16
+ class TestRailsAutolink < Minitest::Test
17
17
  include ActionView::Helpers::CaptureHelper
18
18
  include ActionView::Helpers::TextHelper
19
19
  include ActionView::Helpers::SanitizeHelper
@@ -24,7 +24,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
24
24
 
25
25
  def test_auto_link_within_tags
26
26
  link_raw = 'http://www.rubyonrails.org/images/rails.png'
27
- link_result = %Q(<img src="#{link_raw}" />)
27
+ link_result = %Q(<img src="#{link_raw}">)
28
28
  assert_equal link_result, auto_link(link_result)
29
29
  end
30
30
 
@@ -62,7 +62,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
62
62
  url = "http://api.rubyonrails.com/Foo.html"
63
63
  email = "fantabulous@shiznadel.ic"
64
64
 
65
- assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |_url| truncate(_url, :length => 10) }
65
+ assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br><a href="mailto:#{email}">#{email[0...7]}...</a><br></p>), auto_link("<p>#{url}<br>#{email}<br></p>") { |_url| truncate(_url, :length => 10) }
66
66
  end
67
67
 
68
68
  def test_auto_link_with_block_with_html
@@ -81,7 +81,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
81
81
  def test_auto_link_should_sanitize_input_when_sanitize_option_is_not_false
82
82
  link_raw = %{http://www.rubyonrails.com?id=1&num=2}
83
83
  malicious_script = '<script>alert("malicious!")</script>'
84
- assert_equal %{<a href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a>}, auto_link("#{link_raw}#{malicious_script}")
84
+ assert_equal %{<a href="http://www.rubyonrails.com?id=1&amp;num=2alert">http://www.rubyonrails.com?id=1&amp;num=2alert</a>("malicious!")}, auto_link("#{link_raw}#{malicious_script}")
85
85
  assert auto_link("#{link_raw}#{malicious_script}").html_safe?
86
86
  end
87
87
 
@@ -90,7 +90,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
90
90
  malicious_script = '<script>alert("malicious!")</script>'
91
91
  text_with_attributes = %{<a href="http://ruby-lang-org" target="_blank" data-malicious="inject">Ruby</a>}
92
92
 
93
- text_result = %{<a class="big" href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a><a href="http://ruby-lang-org" target="_blank">Ruby</a>}
93
+ text_result = %{<a class="big" href="http://www.rubyonrails.com?id=1&amp;num=2alert">http://www.rubyonrails.com?id=1&amp;num=2alert</a>("malicious!")<a href="http://ruby-lang-org" target="_blank">Ruby</a>}
94
94
  assert_equal text_result, auto_link("#{link_raw}#{malicious_script}#{text_with_attributes}",
95
95
  :sanitize_options => {:attributes => ["target", "href"]},
96
96
  :html => {:class => 'big'})
@@ -146,7 +146,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
146
146
  url1 = "http://api.rubyonrails.com/Foo.html"
147
147
  url2 = "http://www.ruby-doc.org/core/Bar.html"
148
148
 
149
- assert_equal %(<p><a href="#{url1}">#{url1}</a><br /><a href="#{url2}">#{url2}</a><br /></p>), auto_link("<p>#{url1}<br />#{url2}<br /></p>")
149
+ assert_equal %(<p><a href="#{url1}">#{url1}</a><br><a href="#{url2}">#{url2}</a><br></p>), auto_link("<p>#{url1}<br>#{url2}<br></p>")
150
150
  end
151
151
 
152
152
  def test_auto_link_should_be_html_safe
@@ -177,14 +177,16 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
177
177
  end
178
178
 
179
179
  def test_auto_link_email_addres_with_especial_chars
180
- email_raw = "and&re$la*+r-a.o'rea=l~ly@tenderlovemaking.com"
180
+ email_raw = "andre$la*+r-a.o'rea=l~ly@tenderlovemaking.com"
181
+ email_raw_encoded = ERB::Util.url_encode("andre$la*+r-a.o'rea=l~ly@tenderlovemaking.com").gsub("%40", "@")
181
182
  email_sanitized = if Rails.version =~ /^3/
182
183
  # mail_to changed the number base it rendered HTML encoded characters at some point
183
- "and&amp;re$la*+r-a.o&#x27;rea=l~ly@tenderlovemaking.com"
184
+ "andre$la*+r-a.o&#x27;rea=l~ly@tenderlovemaking.com"
184
185
  else
185
- "and&amp;re$la*+r-a.o&#39;rea=l~ly@tenderlovemaking.com"
186
+ "andre$la*+r-a.o&#39;rea=l~ly@tenderlovemaking.com"
186
187
  end
187
- email_result = %{<a href="mailto:#{email_raw}">#{email_sanitized}</a>}
188
+ email_result = %{<a href="mailto:#{email_raw_encoded}">#{email_sanitized}</a>}
189
+
188
190
  assert_equal email_result, auto_link(email_raw)
189
191
  assert !auto_link_email_addresses(email_result).html_safe?, 'should not be html safe'
190
192
  end
@@ -194,7 +196,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
194
196
  email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
195
197
  link_raw = 'http://www.rubyonrails.com'
196
198
  link_result = generate_result(link_raw)
197
- link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
199
+ link_result_with_options = %{<a target="_blank" href="#{link_raw}">#{link_raw}</a>}
198
200
 
199
201
  assert_equal '', auto_link(nil)
200
202
  assert_equal '', auto_link('')
@@ -212,7 +214,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
212
214
  assert_equal %(#{link_result} #{link_result}), auto_link(%(#{link_result} #{link_raw}))
213
215
 
214
216
  email2_raw = '+david@loudthinking.com'
215
- email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
217
+ email2_result = %{<a href="mailto:%2Bdavid@loudthinking.com">#{email2_raw}</a>}
216
218
  assert_equal email2_result, auto_link(email2_raw)
217
219
  assert_equal email2_result, auto_link(email2_raw, :all)
218
220
  assert_equal email2_result, auto_link(email2_raw, :email_addresses)
@@ -313,6 +315,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
313
315
  http://of.openfoundry.org/projects/492/download#4th.Release.3
314
316
  http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A
315
317
  http://около.кола/колокола
318
+ https://123domain.com https://123.com https://123.domain.com https://www.123.domain.com
316
319
  )
317
320
 
318
321
  urls.each do |url|
@@ -330,11 +333,35 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
330
333
  assert_equal generate_result(url), auto_link(url)
331
334
  end
332
335
 
336
+ def test_autolink_with_trailing_colon_on_link
337
+ url = "http://www.rubyonrails.com/foo.cgi?trailing_colon=value:"
338
+ expected_url = "http://www.rubyonrails.com/foo.cgi?trailing_colon=value"
339
+
340
+ assert_equal "#{generate_result(expected_url)}:", auto_link(url)
341
+ end
342
+
343
+ def test_autolink_with_trailing_hyphen_on_link
344
+ url = "http://www.rubyonrails.com/foo.cgi?trailing_hyphen=value-"
345
+ assert_equal generate_result(url), auto_link(url)
346
+ end
347
+
348
+ def test_autolink_with_trailing_forward_slash_on_link
349
+ url = "http://www.rubyonrails.com/foo.cgi?trailing_forward_slash=value/"
350
+ assert_equal generate_result(url), auto_link(url)
351
+ end
352
+
353
+ def test_autolink_with_trailing_number_on_link
354
+ url = "http://www.rubyonrails.com/foo.cgi?trailing_number=value3"
355
+ assert_equal generate_result(url), auto_link(url)
356
+ end
357
+
333
358
  def test_auto_link_does_not_timeout_when_parsing_odd_email_input
334
- inputs = %w(
359
+ inputs = %W(
335
360
  foo@...................................
336
361
  foo@........................................
337
362
  foo@.............................................
363
+
364
+ #{'foo' * 20000}@
338
365
  )
339
366
 
340
367
  inputs.each do |input|
@@ -344,14 +371,15 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
344
371
  end
345
372
  end
346
373
 
374
+ def test_auto_link_with_www_in_non_url_string
375
+ assert_equal "awww.", auto_link("awww.")
376
+ end
377
+
347
378
  private
348
- def generate_result(link_text, href = nil, escape = false)
349
- href ||= link_text
350
- if escape
351
- %{<a href="#{CGI::escapeHTML href}">#{CGI::escapeHTML link_text}</a>}
352
- else
353
- %{<a href="#{href}">#{link_text}</a>}
354
- end
379
+ def generate_result(link_text, href = nil)
380
+ text = sanitize(link_text)
381
+ href = sanitize(href) || text
382
+ %{<a href="#{href}">#{text}</a>}.gsub("&#39;", "'") # ActionView does not escape '
355
383
  end
356
384
 
357
385
  # from ruby core
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_autolink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  - Juanjo Bazan
9
9
  - Akira Matsuda
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-08 00:00:00.000000000 Z
13
+ date: 2022-11-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -49,7 +49,7 @@ homepage: https://github.com/tenderlove/rails_autolink
49
49
  licenses:
50
50
  - MIT
51
51
  metadata: {}
52
- post_install_message:
52
+ post_install_message:
53
53
  rdoc_options: []
54
54
  require_paths:
55
55
  - lib
@@ -64,9 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.2.2
69
- signing_key:
67
+ rubygems_version: 3.2.33
68
+ signing_key:
70
69
  specification_version: 4
71
70
  summary: Automatic generation of html links in texts
72
71
  test_files: []