actionview-encoded_mail_to 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81457ed404f7ef4ac2b924a13a7eed04c20e4916
|
4
|
+
data.tar.gz: 4b42593a0733d6142d036ba1d987fa6930adc864
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ddbf2557c87e7b1debd014e21ab2e678411c6293a9ed67064770fbb0a816af3565d48f682d7036f3949499d09cce9be370cd49e46627d95b49a9f6491412194
|
7
|
+
data.tar.gz: 8b4ce8561cc71163f7372d86fe5e1d5fed55328cb7701c94f8e4825ff927efeeffb69a8f369b271225607a76ee0af8ec3ea6b6803cbc59f77d0febb710a1f1c4
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ Use the `mail_to` helper method just as you did prior to Rails 4.0.
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
mail_to "me@domain.com", "My email", encode: "javascript"
|
46
|
-
# => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
|
46
|
+
# => <script id="mail_to-sz6xohiu">eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
|
47
47
|
|
48
48
|
mail_to "me@domain.com", "My email", encode: "hex"
|
49
49
|
# => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
|
@@ -46,19 +46,19 @@ module EncodedMailTo
|
|
46
46
|
# mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
|
47
47
|
# subject: "This is an example email"
|
48
48
|
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
|
49
|
-
def mail_to_with_encoding(email_address, name = nil, html_options = {})
|
49
|
+
def mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
|
50
50
|
html_options.stringify_keys!
|
51
51
|
if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
|
52
|
-
mail_to_without_encoding email_address, name, html_options
|
52
|
+
mail_to_without_encoding email_address, name, html_options, &block
|
53
53
|
else
|
54
|
-
_mail_to_with_encoding email_address, name, html_options
|
54
|
+
_mail_to_with_encoding email_address, name, html_options, &block
|
55
55
|
end
|
56
56
|
end
|
57
57
|
alias_method_chain :mail_to, :encoding
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
-
def _mail_to_with_encoding(email_address, name = nil, html_options = {})
|
61
|
+
def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
|
62
62
|
email_address = ERB::Util.html_escape(email_address)
|
63
63
|
|
64
64
|
encode = html_options.delete("encode").to_s
|
@@ -80,16 +80,22 @@ module EncodedMailTo
|
|
80
80
|
html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe).each_pair do |name,value|
|
81
81
|
set_attributes += "a.setAttribute('#{name}', '#{value}');"
|
82
82
|
end
|
83
|
-
|
84
|
-
|
83
|
+
script_id = rand(36**8).to_s(36)
|
84
|
+
if block_given?
|
85
|
+
block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
|
86
|
+
link_content = "a.innerHTML='#{block_content}';"
|
87
|
+
else
|
88
|
+
link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
|
89
|
+
end
|
90
|
+
create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
|
85
91
|
"var a = document.createElement('a');" +
|
86
92
|
"#{set_attributes}" +
|
87
|
-
|
93
|
+
link_content +
|
88
94
|
"script.parentNode.insertBefore(a,script);"
|
89
95
|
create_link.each_byte do |c|
|
90
96
|
string << sprintf("%%%x", c)
|
91
97
|
end
|
92
|
-
"<script>eval(decodeURIComponent('#{string}'))</script>".html_safe
|
98
|
+
"<script id=\"mail_to-#{script_id}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
|
93
99
|
when "hex"
|
94
100
|
email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
|
95
101
|
sprintf("&#%d;", c)
|
@@ -102,9 +108,9 @@ module EncodedMailTo
|
|
102
108
|
char =~ /\w/ ? sprintf("%%%x", c) : char
|
103
109
|
}.join
|
104
110
|
|
105
|
-
content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe)
|
111
|
+
content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
|
106
112
|
else
|
107
|
-
content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe)
|
113
|
+
content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
|
108
114
|
end
|
109
115
|
end
|
110
116
|
end
|
@@ -6,10 +6,13 @@ require 'action_pack'
|
|
6
6
|
require 'action_view/helpers/capture_helper'
|
7
7
|
require 'action_view/helpers/url_helper'
|
8
8
|
require 'action_view/encoded_mail_to/mail_to_with_encoding'
|
9
|
+
require 'action_view/buffers'
|
9
10
|
|
10
11
|
class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
|
11
12
|
include ActionView::Helpers::UrlHelper
|
12
13
|
|
14
|
+
attr_accessor :output_buffer
|
15
|
+
|
13
16
|
def test_initialization
|
14
17
|
[:mail_to, :mail_to_with_encoding, :mail_to_without_encoding].each do |method|
|
15
18
|
assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
|
@@ -31,18 +34,43 @@ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def test_mail_to_with_javascript
|
34
|
-
|
35
|
-
"
|
37
|
+
assert_match(
|
38
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%4d%79%20%65%6d%61%69%6c%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
36
39
|
mail_to("me@domain.com", "My email", encode: "javascript")
|
37
40
|
)
|
38
41
|
end
|
39
42
|
|
40
43
|
def test_mail_to_with_javascript_unicode
|
41
|
-
|
42
|
-
"
|
44
|
+
assert_match(
|
45
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%c3%ba%6e%69%63%6f%64%65%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
43
46
|
mail_to("unicode@example.com", "únicode", encode: "javascript")
|
44
47
|
)
|
45
48
|
end
|
49
|
+
|
50
|
+
def test_mail_to_with_javascript_and_block
|
51
|
+
output = mail_to("me@example.com", nil, encode: "javascript") do
|
52
|
+
"<i class='icon-mail'></i>".html_safe
|
53
|
+
end
|
54
|
+
assert_match(
|
55
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%27%29%3b%61%2e%69%6e%6e%65%72%48%54%4d%4c%3d%27%3c%69%20%63%6c%61%73%73%3d%5c%27%69%63%6f%6e%2d%6d%61%69%6c%5c%27%3e%3c%2f%69%3e%27%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
56
|
+
output
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_multiple_mail_to_with_javascript
|
61
|
+
first = mail_to("me@domain.com", "My email", encode: "javascript")
|
62
|
+
second = mail_to("me@domain.com", "My email", encode: "javascript")
|
63
|
+
|
64
|
+
assert_match(
|
65
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%4d%79%20%65%6d%61%69%6c%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
66
|
+
first
|
67
|
+
)
|
68
|
+
assert_match(
|
69
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%4d%79%20%65%6d%61%69%6c%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
70
|
+
second
|
71
|
+
)
|
72
|
+
refute_equal first, second
|
73
|
+
end
|
46
74
|
|
47
75
|
def test_mail_with_options
|
48
76
|
assert_equal(
|
@@ -68,6 +96,16 @@ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
|
|
68
96
|
)
|
69
97
|
end
|
70
98
|
|
99
|
+
def test_mail_to_with_hex_and_block
|
100
|
+
output = mail_to("me@example.com", nil, encode: "hex") {
|
101
|
+
"<i class='icon-cog'></i> Contact Us".html_safe
|
102
|
+
}
|
103
|
+
assert_equal(
|
104
|
+
%{<a href="mailto:%6d%65@%65%78%61%6d%70%6c%65.%63%6f%6d\"><i class='icon-cog'></i> Contact Us</a>},
|
105
|
+
output
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
71
109
|
def test_mail_to_with_replace_options
|
72
110
|
assert_equal(
|
73
111
|
%{<a href="mailto:me@domain.com">me(at)domain(dot)com</a>},
|
@@ -89,13 +127,13 @@ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
|
|
89
127
|
mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)", replace_dot: "(dot)")
|
90
128
|
)
|
91
129
|
|
92
|
-
|
93
|
-
|
130
|
+
assert_match(
|
131
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%4d%79%20%65%6d%61%69%6c%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
94
132
|
mail_to("me@domain.com", "My email", encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
|
95
133
|
)
|
96
|
-
|
97
|
-
|
98
|
-
|
134
|
+
|
135
|
+
assert_match(
|
136
|
+
/<script id=\"mail_to-\S+\">eval\(decodeURIComponent\('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%42%79%49%64%28%27%6d%61%69%6c%5f%74%6f%2d\S+%27%29%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'\)\)<\/script>/,
|
99
137
|
mail_to("me@domain.com", nil, encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
|
100
138
|
)
|
101
139
|
end
|
metadata
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionview-encoded_mail_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nick Reed
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: minitest
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
description: Rails mail_to helper with encoding (removed from core in Rails 4.0)
|
37
42
|
email: reednj77@gmail.com
|
38
43
|
executables: []
|
@@ -53,33 +58,26 @@ files:
|
|
53
58
|
- test/test_actionview-encoded_mail_to.rb
|
54
59
|
homepage: https://github.com/reed/actionview-encoded_mail_to
|
55
60
|
licenses: []
|
61
|
+
metadata: {}
|
56
62
|
post_install_message:
|
57
63
|
rdoc_options: []
|
58
64
|
require_paths:
|
59
65
|
- lib
|
60
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
67
|
requirements:
|
63
|
-
- -
|
68
|
+
- - '>='
|
64
69
|
- !ruby/object:Gem::Version
|
65
70
|
version: '0'
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
hash: 4472424837606369379
|
69
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
72
|
requirements:
|
72
|
-
- -
|
73
|
+
- - '>='
|
73
74
|
- !ruby/object:Gem::Version
|
74
75
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: 4472424837606369379
|
78
76
|
requirements: []
|
79
77
|
rubyforge_project:
|
80
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.0.3
|
81
79
|
signing_key:
|
82
|
-
specification_version:
|
80
|
+
specification_version: 4
|
83
81
|
summary: Deprecated support for email address obfuscation within the mail_to helper
|
84
82
|
method.
|
85
83
|
test_files:
|