actionview-encoded_mail_to 1.0.5 → 1.0.6

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
2
  SHA1:
3
- metadata.gz: 04367a07299aab0fe5c6835a0c656cb6cb38a60d
4
- data.tar.gz: 8ae506583897c6bfb67c1c196a653deccf4fa746
3
+ metadata.gz: 2be7e7ec2f9a72bfbd74cdb19caa9fb1b32b4e1e
4
+ data.tar.gz: c09ef047805e6a175ff09bb3cac67e0217308046
5
5
  SHA512:
6
- metadata.gz: d70122653906db2e2612740fe767c016210a5e84f3903f9cfcb597cf90bb3a3b890eb16007cbf1a6f63b4fa8932f8ac3a544faea5c26f493fccd8bdbd8177ae6
7
- data.tar.gz: 7bc35f5cd72a467c636817d2e6cdc34718fbe07e618f575e080af328abfc60b5fef33124f1c1af00129e3e6cb2a38482a56e603a79fdf3cb1eedf74a7c27cbb2
6
+ metadata.gz: 73737a026c559aed3b64a711e7ca32478c53fc3993570766a1356c0c13085f6cd06d5c73330f29e6387d6f317067b843e18d5d4b8aab0d73447a6d45dbeebcac
7
+ data.tar.gz: 228c73383244b3335acbf85ccc94b2c81643ae03b74b8b47b6e818ebf5880f5f46240f507dd26af0fc13d28624b8b2a5c3f303e9059184b441363d23e7313a8a
@@ -47,6 +47,7 @@ module EncodedMailTo
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
49
  def mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
50
+ html_options, name = name, nil if block_given? && html_options.blank?
50
51
  html_options.stringify_keys!
51
52
  if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
52
53
  mail_to_without_encoding email_address, name, html_options, &block
@@ -55,24 +56,24 @@ module EncodedMailTo
55
56
  end
56
57
  end
57
58
  alias_method_chain :mail_to, :encoding
58
-
59
+
59
60
  private
60
-
61
+
61
62
  def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
62
63
  email_address = ERB::Util.html_escape(email_address)
63
-
64
+
64
65
  encode = html_options.delete("encode").to_s
65
-
66
+
66
67
  extras = %w{ cc bcc body subject }.map { |item|
67
68
  option = html_options.delete(item) || next
68
- "#{item}=#{Rack::Utils.escape_path(option)}"
69
+ ERB::Util.html_escape "#{item}=#{Rack::Utils.escape_path(option)}"
69
70
  }.compact
70
- extras = extras.empty? ? '' : '?' + ERB::Util.html_escape(extras.join('&'))
71
-
71
+ extras = extras.empty? ? '' : '?' + extras.join('&')
72
+
72
73
  email_address_obfuscated = email_address.to_str
73
74
  email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
74
75
  email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
75
-
76
+
76
77
  case encode
77
78
  when "javascript"
78
79
  string = ''
@@ -89,7 +90,7 @@ module EncodedMailTo
89
90
  end
90
91
  create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
91
92
  "var a = document.createElement('a');" +
92
- "#{set_attributes}" +
93
+ "#{set_attributes}" +
93
94
  link_content +
94
95
  "script.parentNode.insertBefore(a,script);"
95
96
  create_link.each_byte do |c|
@@ -100,14 +101,14 @@ module EncodedMailTo
100
101
  email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
101
102
  sprintf("&#%d;", c)
102
103
  }.join
103
-
104
+
104
105
  string = 'mailto:'.unpack('C*').map { |c|
105
106
  sprintf("&#%d;", c)
106
107
  }.join + email_address.unpack('C*').map { |c|
107
108
  char = c.chr
108
109
  char =~ /\w/ ? sprintf("%%%x", c) : char
109
110
  }.join
110
-
111
+
111
112
  content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
112
113
  else
113
114
  content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
@@ -116,4 +117,4 @@ module EncodedMailTo
116
117
  end
117
118
  end
118
119
  end
119
- end
120
+ end
@@ -1,5 +1,5 @@
1
1
  module ActionView
2
2
  module EncodedMailTo
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  end
@@ -4,13 +4,14 @@ require 'minitest/autorun'
4
4
  require 'rails'
5
5
  require 'action_pack'
6
6
  require 'action_view/helpers/capture_helper'
7
+ require 'action_view/helpers/output_safety_helper'
7
8
  require 'action_view/helpers/url_helper'
8
9
  require 'action_view/encoded_mail_to/mail_to_with_encoding'
9
10
  require 'action_view/buffers'
10
11
 
11
12
  class TestActionViewEncodedMailTo < MiniTest::Test
12
13
  include ActionView::Helpers::UrlHelper
13
-
14
+
14
15
  attr_accessor :output_buffer
15
16
 
16
17
  def test_initialization
@@ -18,7 +19,7 @@ class TestActionViewEncodedMailTo < MiniTest::Test
18
19
  assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
19
20
  end
20
21
  end
21
-
22
+
22
23
  def test_mail_to
23
24
  assert_equal %{<a href="mailto:nick@example.com">nick@example.com</a>}, mail_to("nick@example.com")
24
25
  assert_equal %{<a href="mailto:nick@example.com">Nick Reed</a>}, mail_to("nick@example.com", "Nick Reed")
@@ -27,26 +28,26 @@ class TestActionViewEncodedMailTo < MiniTest::Test
27
28
  assert_equal mail_to("nick@example.com", "Nick Reed", "class" => "admin"),
28
29
  mail_to("nick@example.com", "Nick Reed", class: "admin")
29
30
  end
30
-
31
+
31
32
  def test_mail_to_without_encoding
32
33
  assert_equal mail_to("nick@example.com", "Nick Reed"),
33
34
  mail_to_without_encoding("nick@example.com", "Nick Reed")
34
35
  end
35
-
36
+
36
37
  def test_mail_to_with_javascript
37
38
  assert_match(
38
39
  /<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>/,
39
40
  mail_to("me@domain.com", "My email", encode: "javascript")
40
41
  )
41
42
  end
42
-
43
+
43
44
  def test_mail_to_with_javascript_unicode
44
45
  assert_match(
45
46
  /<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>/,
46
47
  mail_to("unicode@example.com", "únicode", encode: "javascript")
47
48
  )
48
49
  end
49
-
50
+
50
51
  def test_mail_to_with_javascript_and_block
51
52
  output = mail_to("me@example.com", nil, encode: "javascript") do
52
53
  "<i class='icon-mail'></i>".html_safe
@@ -57,10 +58,20 @@ class TestActionViewEncodedMailTo < MiniTest::Test
57
58
  )
58
59
  end
59
60
 
61
+ def test_mail_to_with_javascript_and_block_excluding_name_argument
62
+ output = mail_to("me@example.com", encode: "javascript") do
63
+ "<i class='icon-mail'></i>".html_safe
64
+ end
65
+ assert_match(
66
+ /<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>/,
67
+ output
68
+ )
69
+ end
70
+
60
71
  def test_multiple_mail_to_with_javascript
61
72
  first = mail_to("me@domain.com", "My email", encode: "javascript")
62
73
  second = mail_to("me@domain.com", "My email", encode: "javascript")
63
-
74
+
64
75
  assert_match(
65
76
  /<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
77
  first
@@ -71,31 +82,31 @@ class TestActionViewEncodedMailTo < MiniTest::Test
71
82
  )
72
83
  refute_equal first, second
73
84
  end
74
-
85
+
75
86
  def test_mail_with_options
76
87
  assert_equal(
77
88
  %{<a href="mailto:me@example.com?cc=ccaddress%40example.com&amp;bcc=bccaddress%40example.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email">My email</a>},
78
89
  mail_to("me@example.com", "My email", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message.")
79
90
  )
80
91
  end
81
-
92
+
82
93
  def test_mail_to_with_img
83
94
  assert_equal %{<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>},
84
95
  mail_to('feedback@example.com', '<img src="/feedback.png" />'.html_safe)
85
96
  end
86
-
97
+
87
98
  def test_mail_to_with_hex
88
99
  assert_equal(
89
100
  %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>},
90
101
  mail_to("me@domain.com", "My email", encode: "hex")
91
102
  )
92
-
103
+
93
104
  assert_equal(
94
105
  %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">&#109;&#101;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;</a>},
95
106
  mail_to("me@domain.com", nil, encode: "hex")
96
107
  )
97
108
  end
98
-
109
+
99
110
  def test_mail_to_with_hex_and_block
100
111
  output = mail_to("me@example.com", nil, encode: "hex") {
101
112
  "<i class='icon-cog'></i> Contact Us".html_safe
@@ -111,37 +122,37 @@ class TestActionViewEncodedMailTo < MiniTest::Test
111
122
  %{<a href="mailto:me@domain.com">me(at)domain(dot)com</a>},
112
123
  mail_to("me@domain.com", nil, replace_at: "(at)", replace_dot: "(dot)")
113
124
  )
114
-
125
+
115
126
  assert_equal(
116
127
  %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;</a>},
117
128
  mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)")
118
129
  )
119
-
130
+
120
131
  assert_equal(
121
132
  %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>},
122
133
  mail_to("me@domain.com", "My email", encode: "hex", replace_at: "(at)")
123
134
  )
124
-
135
+
125
136
  assert_equal(
126
137
  %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#40;&#100;&#111;&#116;&#41;&#99;&#111;&#109;</a>},
127
138
  mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)", replace_dot: "(dot)")
128
139
  )
129
-
140
+
130
141
  assert_match(
131
142
  /<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>/,
132
143
  mail_to("me@domain.com", "My email", encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
133
144
  )
134
-
145
+
135
146
  assert_match(
136
147
  /<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>/,
137
148
  mail_to("me@domain.com", nil, encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
138
149
  )
139
150
  end
140
-
151
+
141
152
  def test_mail_to_returns_html_safe_string
142
153
  assert mail_to("me@domain.com").html_safe?
143
154
  assert mail_to("me@domain.com", "My email", encode: "javascript").html_safe?
144
155
  assert mail_to("me@domain.com", "My email", encode: "hex").html_safe?
145
156
  end
146
-
147
- end
157
+
158
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
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
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Reed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2015-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails