checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 895b6d9a2de55ebfa5c7e7bfab7aeced22515182
4
+ data.tar.gz: f3f6b8d6aa7782edee26a6a8b95236990b65c5ac
5
+ SHA512:
6
+ metadata.gz: 92306721ad1c635bfabea24f8bf74c52252220b70c92966b51a77e7e4df101c9ae586e14f1ebe536db3912fe95fa132f777c6846a14086c5bce3466f237e0e6c
7
+ data.tar.gz: 31903eb995c19c454a2d7295ea35672052f9339ce009dd81c06369bf202bc4d5cee8a89f13aa20beaaabce523a143cd97c498e86099551a70e6c45813e248640
data/.autotest ADDED
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = 'minitest/autorun'
7
+ at.find_directories = ARGV unless ARGV.empty?
8
+ end
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache:
4
+ - bundler
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.10
8
+ - 2.2.5
9
+ - 2.3.1
10
+ before_install: gem update bundler
11
+ script: bundle exec rake test
12
+ env:
13
+ matrix:
14
+ - RAILS_VERSION="~> 4.0.0"
15
+ - RAILS_VERSION="~> 4.1.0"
16
+ - RAILS_VERSION="~> 4.2.0"
17
+ - RAILS_VERSION="~> 5.0.0"
18
+ matrix:
19
+ exclude:
20
+ - rvm: 2.0.0
21
+ env: RAILS_VERSION="~> 5.0.0"
22
+ - rvm: 2.1.10
23
+ env: RAILS_VERSION="~> 5.0.0"
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'railties', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
6
+ gem 'mime-types', '~> 2' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0')
7
+ gem 'rack', '~> 1' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nick Reed
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # actionview-encoded_mail_to
2
+ [![Build Status](https://secure.travis-ci.org/reed/actionview-encoded_mail_to.png)](http://travis-ci.org/reed/actionview-encoded_mail_to)
3
+
4
+ Deprecated support for email address obfuscation within the **mail_to** helper method. Restores the options `:encode`, `:replace_at`, and `:replace_dot`, which were removed from Rails in version 4.0.
5
+
6
+ Any call to **mail_to** that _doesn't_ include any of these options will be passed through to the core **mail_to** helper (in [ActionView::Helpers::UrlHelper](https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/url_helper.rb)).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'actionview-encoded_mail_to'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install actionview-encoded_mail_to
21
+
22
+ ## Usage
23
+
24
+ Use the `mail_to` helper method just as you did prior to Rails 4.0.
25
+
26
+ #### Restored Options
27
+
28
+ * `:encode` - This key will accept the strings "javascript" or "hex".
29
+ Passing "javascript" will dynamically create and encode the mailto link then
30
+ eval it into the DOM of the page. This method will not show the link on
31
+ the page if the user has JavaScript disabled. Passing "hex" will hex
32
+ encode the email_address before outputting the mailto link.
33
+ * `:replace_at` - When the link name isn't provided, the
34
+ email_address is used for the link label. You can use this option to
35
+ obfuscate the email_address by substituting the @ sign with the string
36
+ given as the value.
37
+ * `:replace_dot` - When the link name isn't provided, the
38
+ email_address is used for the link label. You can use this option to
39
+ obfuscate the email_address by substituting the `.` in the email with the
40
+ string given as the value.
41
+
42
+ #### Examples
43
+
44
+ ```ruby
45
+ mail_to "me@domain.com", "My email", encode: "javascript"
46
+ # => <script id="mail_to-sz6xohiu">eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
47
+
48
+ mail_to "me@domain.com", "My email", encode: "hex"
49
+ # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
50
+
51
+ mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
52
+ # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/test_*.rb'
7
+ end
data/actionview-encoded_mail_to.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/action_view/encoded_mail_to/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'actionview-encoded_mail_to'
6
+ s.version = ActionView::EncodedMailTo::VERSION
7
+ s.authors = 'Nick Reed'
8
+ s.email = 'reednj77@gmail.com'
9
+ s.description = %q{Rails mail_to helper with encoding (removed from core in Rails 4.0)}
10
+ s.summary = %q{Deprecated support for email address obfuscation within the mail_to helper method.}
11
+ s.homepage = 'https://github.com/reed/actionview-encoded_mail_to'
12
+
13
+ s.add_dependency 'rails'
14
+ s.add_development_dependency 'minitest'
15
+
16
+ s.required_ruby_version = '>= 2.0.0'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.require_paths = ["lib"]
21
+ end
data/lib/action_view/encoded_mail_to/mail_to_with_encoding.rb ADDED
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+ module ActionView
3
+ module EncodedMailTo
4
+ module MailToWithEncoding
5
+ # Creates a mailto link tag to the specified +email_address+, which is
6
+ # also used as the name of the link unless +name+ is specified. Additional
7
+ # HTML attributes for the link can be passed in +html_options+.
8
+ #
9
+ # +mail_to+ has several methods for hindering email harvesters and customizing
10
+ # the email itself by passing special keys to +html_options+.
11
+ #
12
+ # ==== Options
13
+ # * <tt>:encode</tt> - This key will accept the strings "javascript" or "hex".
14
+ # Passing "javascript" will dynamically create and encode the mailto link then
15
+ # eval it into the DOM of the page. This method will not show the link on
16
+ # the page if the user has JavaScript disabled. Passing "hex" will hex
17
+ # encode the +email_address+ before outputting the mailto link.
18
+ # * <tt>:replace_at</tt> - When the link +name+ isn't provided, the
19
+ # +email_address+ is used for the link label. You can use this option to
20
+ # obfuscate the +email_address+ by substituting the @ sign with the string
21
+ # given as the value.
22
+ # * <tt>:replace_dot</tt> - When the link +name+ isn't provided, the
23
+ # +email_address+ is used for the link label. You can use this option to
24
+ # obfuscate the +email_address+ by substituting the . in the email with the
25
+ # string given as the value.
26
+ # * <tt>:subject</tt> - Preset the subject line of the email.
27
+ # * <tt>:body</tt> - Preset the body of the email.
28
+ # * <tt>:cc</tt> - Carbon Copy additional recipients on the email.
29
+ # * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
30
+ #
31
+ # ==== Examples
32
+ # mail_to "me@domain.com"
33
+ # # => <a href="mailto:me@domain.com">me@domain.com</a>
34
+ #
35
+ # mail_to "me@domain.com", "My email", encode: "javascript"
36
+ # # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
37
+ #
38
+ # mail_to "me@domain.com", "My email", encode: "hex"
39
+ # # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
40
+ #
41
+ # mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
42
+ # # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
43
+ #
44
+ # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
45
+ # subject: "This is an example email"
46
+ # # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
47
+ def mail_to(email_address, name = nil, html_options = {}, &block)
48
+ html_options, name = name || {}, nil if block_given? && html_options.blank?
49
+ html_options.stringify_keys!
50
+ if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
51
+ super email_address, name, html_options, &block
52
+ else
53
+ _mail_to_with_encoding email_address, name, html_options, &block
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
60
+ email_address = ERB::Util.html_escape(email_address)
61
+
62
+ encode = html_options.delete("encode").to_s
63
+
64
+ extras = %w{ cc bcc body subject }.map { |item|
65
+ option = html_options.delete(item) || next
66
+ ERB::Util.html_escape "#{item}=#{Rack::Utils.escape_path(option)}"
67
+ }.compact
68
+ extras = extras.empty? ? '' : '?' + extras.join('&')
69
+
70
+ email_address_obfuscated = email_address.to_str
71
+ email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
72
+ email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
73
+
74
+ case encode
75
+ when "javascript"
76
+ string = ''
77
+ set_attributes = ''
78
+ html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe).each_pair do |option_name,value|
79
+ set_attributes += "a.setAttribute('#{option_name}', '#{value}');"
80
+ end
81
+ script_id = rand(36**8).to_s(36)
82
+ if block_given?
83
+ block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
84
+ link_content = "a.innerHTML='#{block_content}';"
85
+ else
86
+ link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
87
+ end
88
+ create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
89
+ "var a = document.createElement('a');" +
90
+ "#{set_attributes}" +
91
+ link_content +
92
+ "script.parentNode.insertBefore(a,script);"
93
+ create_link.each_byte do |c|
94
+ string << sprintf("%%%x", c)
95
+ end
96
+ "<script id=\"mail_to-#{script_id}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
97
+ when "hex"
98
+ email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
99
+ sprintf("&#%d;", c)
100
+ }.join
101
+
102
+ string = 'mailto:'.unpack('C*').map { |c|
103
+ sprintf("&#%d;", c)
104
+ }.join + email_address.unpack('C*').map { |c|
105
+ char = c.chr
106
+ char =~ /\w/ ? sprintf("%%%x", c) : char
107
+ }.join
108
+
109
+ content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
110
+ else
111
+ content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
data/lib/action_view/encoded_mail_to/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module ActionView
2
+ module EncodedMailTo
3
+ VERSION = "1.0.9"
4
+ end
5
+ end
data/lib/actionview-encoded_mail_to.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "action_view/encoded_mail_to/version"
2
+
3
+ module ActionView
4
+ module EncodedMailTo
5
+ class Engine < ::Rails::Engine
6
+ initializer 'actionview-encoded_mail_to' do |app|
7
+ ActiveSupport.on_load(:action_view) do
8
+ require 'action_view/encoded_mail_to/mail_to_with_encoding'
9
+ ActionView::RoutingUrlFor.send :prepend, ActionView::EncodedMailTo::MailToWithEncoding
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
data/test/test_actionview-encoded_mail_to.rb ADDED
@@ -0,0 +1,156 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/autorun'
4
+ require 'rails'
5
+ require 'action_pack'
6
+ require 'action_view'
7
+ require 'action_view/encoded_mail_to/mail_to_with_encoding'
8
+ ActionView::Helpers::UrlHelper.module_eval do
9
+ prepend ActionView::EncodedMailTo::MailToWithEncoding
10
+ end
11
+
12
+ class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
13
+ include ActionView::Helpers::UrlHelper
14
+
15
+ attr_accessor :output_buffer
16
+
17
+ def test_mail_to
18
+ assert_equal %{<a href="mailto:nick@example.com">nick@example.com</a>}, mail_to("nick@example.com")
19
+ assert_equal %{<a href="mailto:nick@example.com">Nick Reed</a>}, mail_to("nick@example.com", "Nick Reed")
20
+ assert_equal %{<a class="admin" href="mailto:nick@example.com">Nick Reed</a>},
21
+ mail_to("nick@example.com", "Nick Reed", "class" => "admin")
22
+ assert_equal mail_to("nick@example.com", "Nick Reed", "class" => "admin"),
23
+ mail_to("nick@example.com", "Nick Reed", class: "admin")
24
+ end
25
+
26
+ def test_mail_to_with_block
27
+ assert_equal(%{<a href="mailto:nick@example.com">Nick</a>}, mail_to("nick@example.com"){'Nick'})
28
+ end
29
+
30
+ def test_mail_to_without_encoding
31
+ assert_equal mail_to("nick@example.com", "Nick Reed"),
32
+ "<a href=\"mailto:nick@example.com\">Nick Reed</a>"
33
+ end
34
+
35
+ def test_mail_to_with_javascript
36
+ assert_match(
37
+ /<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>/,
38
+ mail_to("me@domain.com", "My email", encode: "javascript")
39
+ )
40
+ end
41
+
42
+ def test_mail_to_with_javascript_unicode
43
+ assert_match(
44
+ /<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>/,
45
+ mail_to("unicode@example.com", "Ășnicode", encode: "javascript")
46
+ )
47
+ end
48
+
49
+ def test_mail_to_with_javascript_and_block
50
+ output = mail_to("me@example.com", nil, encode: "javascript") do
51
+ "<i class='icon-mail'></i>".html_safe
52
+ end
53
+ assert_match(
54
+ /<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>/,
55
+ output
56
+ )
57
+ end
58
+
59
+ def test_mail_to_with_javascript_and_block_excluding_name_argument
60
+ output = mail_to("me@example.com", encode: "javascript") do
61
+ "<i class='icon-mail'></i>".html_safe
62
+ end
63
+ assert_match(
64
+ /<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>/,
65
+ output
66
+ )
67
+ end
68
+
69
+ def test_multiple_mail_to_with_javascript
70
+ first = mail_to("me@domain.com", "My email", encode: "javascript")
71
+ second = mail_to("me@domain.com", "My email", encode: "javascript")
72
+
73
+ assert_match(
74
+ /<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>/,
75
+ first
76
+ )
77
+ assert_match(
78
+ /<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>/,
79
+ second
80
+ )
81
+ refute_equal first, second
82
+ end
83
+
84
+ def test_mail_with_options
85
+ assert_equal(
86
+ %{<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>},
87
+ 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.")
88
+ )
89
+ end
90
+
91
+ def test_mail_to_with_img
92
+ assert_equal %{<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>},
93
+ mail_to('feedback@example.com', '<img src="/feedback.png" />'.html_safe)
94
+ end
95
+
96
+ def test_mail_to_with_hex
97
+ assert_equal(
98
+ %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>},
99
+ mail_to("me@domain.com", "My email", encode: "hex")
100
+ )
101
+
102
+ assert_equal(
103
+ %{<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>},
104
+ mail_to("me@domain.com", nil, encode: "hex")
105
+ )
106
+ end
107
+
108
+ def test_mail_to_with_hex_and_block
109
+ output = mail_to("me@example.com", nil, encode: "hex") {
110
+ "<i class='icon-cog'></i> Contact Us".html_safe
111
+ }
112
+ assert_equal(
113
+ %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%65%78%61%6d%70%6c%65.%63%6f%6d\"><i class='icon-cog'></i> Contact Us</a>},
114
+ output
115
+ )
116
+ end
117
+
118
+ def test_mail_to_with_replace_options
119
+ assert_equal(
120
+ %{<a href="mailto:me@domain.com">me(at)domain(dot)com</a>},
121
+ mail_to("me@domain.com", nil, replace_at: "(at)", replace_dot: "(dot)")
122
+ )
123
+
124
+ assert_equal(
125
+ %{<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>},
126
+ mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)")
127
+ )
128
+
129
+ assert_equal(
130
+ %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>},
131
+ mail_to("me@domain.com", "My email", encode: "hex", replace_at: "(at)")
132
+ )
133
+
134
+ assert_equal(
135
+ %{<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>},
136
+ mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)", replace_dot: "(dot)")
137
+ )
138
+
139
+ assert_match(
140
+ /<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>/,
141
+ mail_to("me@domain.com", "My email", encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
142
+ )
143
+
144
+ assert_match(
145
+ /<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>/,
146
+ mail_to("me@domain.com", nil, encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
147
+ )
148
+ end
149
+
150
+ def test_mail_to_returns_html_safe_string
151
+ assert mail_to("me@domain.com").html_safe?
152
+ assert mail_to("me@domain.com", "My email", encode: "javascript").html_safe?
153
+ assert mail_to("me@domain.com", "My email", encode: "hex").html_safe?
154
+ end
155
+
156
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actionview-encoded_mail_to
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Nick Reed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rails mail_to helper with encoding (removed from core in Rails 4.0)
42
+ email: reednj77@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".autotest"
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - actionview-encoded_mail_to.gemspec
55
+ - lib/action_view/encoded_mail_to/mail_to_with_encoding.rb
56
+ - lib/action_view/encoded_mail_to/version.rb
57
+ - lib/actionview-encoded_mail_to.rb
58
+ - test/test_actionview-encoded_mail_to.rb
59
+ homepage: https://github.com/reed/actionview-encoded_mail_to
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.0.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Deprecated support for email address obfuscation within the mail_to helper
82
+ method.
83
+ test_files:
84
+ - test/test_actionview-encoded_mail_to.rb