friendlyfashion-rails_autolink 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/lib/rails_autolink/helpers.rb +12 -4
- data/rails_autolink.gemspec +3 -3
- data/test/test_rails_autolink.rb +24 -6
- metadata +4 -2
data/CHANGELOG.rdoc
CHANGED
@@ -15,7 +15,7 @@ module RailsAutolink
|
|
15
15
|
# <tt>:email_addresses</tt>, and <tt>:urls</tt>. If a block is given, each URL and
|
16
16
|
# e-mail address is yielded and the result is used as the link text. By default the
|
17
17
|
# text given is sanitized, you can override this behaviour setting the
|
18
|
-
# <tt>:sanitize</tt> option to false, or you can add options to the sanitization of
|
18
|
+
# <tt>:sanitize</tt> option to false, or you can add options to the sanitization of
|
19
19
|
# the text using the <tt>:sanitize_options</tt> option hash.
|
20
20
|
#
|
21
21
|
# ==== Examples
|
@@ -106,9 +106,17 @@ module RailsAutolink
|
|
106
106
|
end
|
107
107
|
|
108
108
|
link_text = block_given?? yield(href) : href
|
109
|
+
|
110
|
+
custom_link_attributes = link_attributes
|
111
|
+
|
109
112
|
if link_text.is_a?(Hash)
|
110
|
-
|
111
|
-
link_text
|
113
|
+
|
114
|
+
if link_text[:html_options] && link_text[:html_options].is_a?(Hash)
|
115
|
+
custom_link_attributes = link_text[:html_options].stringify_keys
|
116
|
+
end
|
117
|
+
|
118
|
+
href = link_text[:href] || href
|
119
|
+
link_text = link_text[:text] || href
|
112
120
|
else
|
113
121
|
href = 'http://' + href unless scheme
|
114
122
|
end
|
@@ -117,7 +125,7 @@ module RailsAutolink
|
|
117
125
|
link_text = sanitize(link_text)
|
118
126
|
href = sanitize(href)
|
119
127
|
end
|
120
|
-
content_tag(:a, link_text,
|
128
|
+
content_tag(:a, link_text, custom_link_attributes.merge('href' => href), !!options[:sanitize]) + punctuation.reverse.join('')
|
121
129
|
end
|
122
130
|
end
|
123
131
|
end
|
data/rails_autolink.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'friendlyfashion-rails_autolink'
|
3
|
-
s.version = '1.0.
|
4
|
-
s.authors = ["Laurynas Butkus", "Tomas Didziokas", "Justas Janauskas", "Edvinas Bartkus"]
|
5
|
-
s.email = ["laurynas.butkus@gmail.com", "tomas.did@gmail.com", "jjanauskas@gmail.com", "edvinas.bartkus@gmail.com"]
|
3
|
+
s.version = '1.0.12'
|
4
|
+
s.authors = ["Laurynas Butkus", "Tomas Didziokas", "Justas Janauskas", "Edvinas Bartkus", "Andrius Janauskas"]
|
5
|
+
s.email = ["laurynas.butkus@gmail.com", "tomas.did@gmail.com", "jjanauskas@gmail.com", "edvinas.bartkus@gmail.com", "andrius.janauskas@gmail.com"]
|
6
6
|
s.summary = 'This is an extraction of the `auto_link` method from rails. The `auto_link` method was removed from Rails in version Rails 3.1. This gem is meant to bridge the gap for people migrating.'
|
7
7
|
|
8
8
|
s.add_dependency 'rails', '> 3.1'
|
data/test/test_rails_autolink.rb
CHANGED
@@ -58,6 +58,24 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
|
|
58
58
|
assert_equal '<a href="http://www.facebook.com">www.facebook.com</a>', result
|
59
59
|
end
|
60
60
|
|
61
|
+
def test_auto_link_with_block_which_returns_hash_with_html_options
|
62
|
+
url = 'http://www.google.com/'
|
63
|
+
result = auto_link(url) do |it|
|
64
|
+
{ text: "www.facebook.com", href: "http://www.facebook.com", html_options: { rel: "nofollow" } }
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_equal '<a href="http://www.facebook.com" rel="nofollow">www.facebook.com</a>', result
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_auto_link_with_block_which_returns_hash_with_html_options_override
|
71
|
+
url = 'http://www.google.com/'
|
72
|
+
result = auto_link(url, { rel: "nofollow" }) do |it|
|
73
|
+
{ text: "www.facebook.com", href: "http://www.facebook.com", html_options: { } }
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_equal '<a href="http://www.facebook.com">www.facebook.com</a>', result
|
77
|
+
end
|
78
|
+
|
61
79
|
def test_auto_link_with_options_hash
|
62
80
|
assert_dom_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com" class="menu" target="_blank">me@email.com</a>.',
|
63
81
|
auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
|
@@ -97,17 +115,17 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
|
|
97
115
|
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}")
|
98
116
|
assert auto_link("#{link_raw}#{malicious_script}").html_safe?
|
99
117
|
end
|
100
|
-
|
118
|
+
|
101
119
|
def test_auto_link_should_sanitize_input_with_sanitize_options
|
102
120
|
link_raw = %{http://www.rubyonrails.com?id=1&num=2}
|
103
121
|
malicious_script = '<script>alert("malicious!")</script>'
|
104
122
|
text_with_attributes = %{<a href="http://ruby-lang-org" target="_blank" data-malicious="inject">Ruby</a>}
|
105
|
-
|
123
|
+
|
106
124
|
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>}
|
107
125
|
assert_equal text_result, auto_link("#{link_raw}#{malicious_script}#{text_with_attributes}",
|
108
126
|
:sanitize_options => {:attributes => ["target", "href"]},
|
109
127
|
:html => {:class => 'big'})
|
110
|
-
|
128
|
+
|
111
129
|
assert auto_link("#{link_raw}#{malicious_script}#{text_with_attributes}",
|
112
130
|
:sanitize_options => {:attributes => ["target", "href"]},
|
113
131
|
:html => {:class => 'big'}).html_safe?
|
@@ -116,7 +134,7 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
|
|
116
134
|
def test_auto_link_should_not_sanitize_input_when_sanitize_option_is_false
|
117
135
|
link_raw = %{http://www.rubyonrails.com?id=1&num=2}
|
118
136
|
malicious_script = '<script>alert("malicious!")</script>'
|
119
|
-
|
137
|
+
|
120
138
|
assert_equal %{<a href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a><script>alert("malicious!")</script>}, auto_link("#{link_raw}#{malicious_script}", :sanitize => false)
|
121
139
|
assert !auto_link("#{link_raw}#{malicious_script}", :sanitize => false).html_safe?
|
122
140
|
end
|
@@ -165,14 +183,14 @@ class TestRailsAutolink < MiniTest::Unit::TestCase
|
|
165
183
|
email_raw = 'santiago@wyeworks.com'
|
166
184
|
link_raw = 'http://www.rubyonrails.org'
|
167
185
|
malicious_script = '<script>alert("malicious!")</script>'
|
168
|
-
|
186
|
+
|
169
187
|
assert auto_link(nil).html_safe?, 'should be html safe'
|
170
188
|
assert auto_link('').html_safe?, 'should be html safe'
|
171
189
|
assert auto_link("#{link_raw} #{link_raw} #{link_raw}").html_safe?, 'should be html safe'
|
172
190
|
assert auto_link("hello #{email_raw}").html_safe?, 'should be html safe'
|
173
191
|
assert auto_link("hello #{email_raw} #{malicious_script}").html_safe?, 'should be html safe'
|
174
192
|
end
|
175
|
-
|
193
|
+
|
176
194
|
def test_auto_link_should_not_be_html_safe_when_sanitize_option_false
|
177
195
|
email_raw = 'santiago@wyeworks.com'
|
178
196
|
link_raw = 'http://www.rubyonrails.org'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendlyfashion-rails_autolink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,11 @@ authors:
|
|
9
9
|
- Tomas Didziokas
|
10
10
|
- Justas Janauskas
|
11
11
|
- Edvinas Bartkus
|
12
|
+
- Andrius Janauskas
|
12
13
|
autorequire:
|
13
14
|
bindir: bin
|
14
15
|
cert_chain: []
|
15
|
-
date: 2013-
|
16
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
16
17
|
dependencies:
|
17
18
|
- !ruby/object:Gem::Dependency
|
18
19
|
name: rails
|
@@ -36,6 +37,7 @@ email:
|
|
36
37
|
- tomas.did@gmail.com
|
37
38
|
- jjanauskas@gmail.com
|
38
39
|
- edvinas.bartkus@gmail.com
|
40
|
+
- andrius.janauskas@gmail.com
|
39
41
|
executables: []
|
40
42
|
extensions: []
|
41
43
|
extra_rdoc_files: []
|