gr_autolink 1.0.7 → 1.0.8

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.
data/README.rdoc CHANGED
@@ -23,7 +23,7 @@ parent gem we forked from:
23
23
 
24
24
  By default gr_autolink returns retains html-safeness of input strings.
25
25
 
26
- This is original gem's behavior and this gem does NOT include this behavio:
26
+ This is original gem's behavior and this gem does NOT include this behavior:
27
27
 
28
28
  * This behaviour can be overriden setting the <tt>:sanitize</tt> option to false
29
29
  (thus making it insecure if you don't have the content under control).
data/lib/gr_autolink.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GrAutolink
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
 
4
4
  class Railtie < ::Rails::Railtie
5
5
  initializer 'gr_autolink' do |app|
@@ -50,6 +50,8 @@ module GrAutolink
50
50
  def auto_link(text, *args, &block)#link = :all, html = {}, &block)
51
51
  return ''.html_safe if text.blank?
52
52
 
53
+ input_html_safe = text.html_safe?
54
+
53
55
  options = args.size == 2 ? {} : args.extract_options! # this is necessary because the old auto_link API has a Hash as its last parameter
54
56
  unless args.empty?
55
57
  options[:link] = args[0] || :all
@@ -59,11 +61,20 @@ module GrAutolink
59
61
  sanitize = (options[:sanitize] != false)
60
62
  sanitize_options = options[:sanitize_options] || {}
61
63
  text = conditional_sanitize(text, sanitize, sanitize_options).to_str
62
- case options[:link].to_sym
63
- when :all then conditional_html_safe(auto_link_email_addresses(auto_link_urls(text, options[:html], options, &block), options[:html], &block), sanitize)
64
- when :email_addresses then conditional_html_safe(auto_link_email_addresses(text, options[:html], &block), sanitize)
65
- when :urls then conditional_html_safe(auto_link_urls(text, options[:html], options, &block), sanitize)
66
- end
64
+
65
+ autolinked_text =
66
+ case options[:link].to_sym
67
+ when :all
68
+ conditional_html_safe(auto_link_email_addresses(auto_link_urls(text, options[:html], options, &block), options[:html], &block), sanitize)
69
+ when :email_addresses
70
+ conditional_html_safe(auto_link_email_addresses(text, options[:html], &block), sanitize)
71
+ when :urls
72
+ conditional_html_safe(auto_link_urls(text, options[:html], options, &block), sanitize)
73
+ end
74
+
75
+ # regardless of sanitizing, make sure output is safe if input was safe
76
+ autolinked_text = input_html_safe ? autolinked_text.html_safe : autolinked_text
77
+ autolinked_text
67
78
  end
68
79
 
69
80
  private
@@ -153,8 +164,8 @@ module GrAutolink
153
164
  condition ? sanitize(target, sanitize_options) : target
154
165
  end
155
166
 
156
- def conditional_html_safe(target, condition)
157
- condition ? target.html_safe : target
167
+ def conditional_html_safe(target, mark_as_html_safe)
168
+ mark_as_html_safe ? target.html_safe : target
158
169
  end
159
170
  end
160
171
  end
@@ -310,6 +310,22 @@ class TestGrAutolink < MiniTest::Unit::TestCase
310
310
  end
311
311
  end
312
312
 
313
+ def test_auto_link_retains_html_safeness_on_strings_with_no_url_sanitize_false
314
+ assert auto_link("abc123".html_safe, :sanitize => false).html_safe?
315
+ end
316
+
317
+ def test_auto_link_retains_non_html_safeness_on_strings_with_no_url_sanitize_false
318
+ assert !auto_link("abc123", :sanitize => false).html_safe?, "converted non-html-safe string to html safe!"
319
+ end
320
+
321
+ def test_auto_link_retains_html_safeness_on_strings_with_urls_to_autolink_sanitize_false
322
+ assert auto_link("my link is http://123.abc.org".html_safe, :sanitize => false).html_safe?
323
+ end
324
+
325
+ def test_auto_link_retains_non_html_safeness_on_strings_with_urls_to_autolink_sanitize_false
326
+ assert !auto_link("my link is http://123.abc.org", :sanitize => false).html_safe?
327
+ end
328
+
313
329
  private
314
330
  def generate_result(link_text, href = nil)
315
331
  href ||= link_text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gr_autolink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,7 +16,7 @@ date: 2012-03-31 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
19
- requirement: &2168727060 !ruby/object:Gem::Requirement
19
+ requirement: &2156556080 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ~>
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '3.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *2168727060
27
+ version_requirements: *2156556080
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rdoc
30
- requirement: &2168726500 !ruby/object:Gem::Requirement
30
+ requirement: &2156555580 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '3.10'
36
36
  type: :development
37
37
  prerelease: false
38
- version_requirements: *2168726500
38
+ version_requirements: *2156555580
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: hoe
41
- requirement: &2168725960 !ruby/object:Gem::Requirement
41
+ requirement: &2156554800 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '2.16'
47
47
  type: :development
48
48
  prerelease: false
49
- version_requirements: *2168725960
49
+ version_requirements: *2156554800
50
50
  description: ! "This is an adaptation of the extraction of the `auto_link` method
51
51
  from rails\nthat is the rails_autolink gem. The `auto_link`\nmethod was removed
52
52
  from Rails in version Rails 3.1. This gem is meant to\nbridge the gap for people