validates_email_format_of 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +10 -6
- data/init.rb +1 -1
- data/lib/validates_email_format_of.rb +9 -6
- data/test/database.yml +3 -0
- data/test/test_helper.rb +1 -3
- data/test/validates_email_format_of_test.rb +34 -6
- metadata +28 -13
- data/rails/init.rb +0 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
= CHANGELOG
|
2
2
|
|
3
|
+
== Version 1.4.2
|
4
|
+
|
5
|
+
* See https://github.com/alexdunae/validates_email_format_of/compare/1.4.1...1.4.2
|
6
|
+
|
3
7
|
== Version 1.4.1 (the George Anderson and 'history' edition)
|
4
8
|
* don't allow domains with underscores
|
5
9
|
* removed extra spaces in validation messages
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -6,13 +6,16 @@ Validate e-mail addresses against RFC 2822 and RFC 3696.
|
|
6
6
|
|
7
7
|
Installing as a gem:
|
8
8
|
|
9
|
-
gem
|
10
|
-
gem install alexdunae-validates_email_format_of
|
9
|
+
gem install validates_email_format_of
|
11
10
|
|
12
|
-
Installing as a Ruby on Rails plugin:
|
11
|
+
Installing as a Ruby on Rails 2 plugin:
|
13
12
|
|
14
13
|
./script/plugin install http://github.com/alexdunae/validates_email_format_of.git
|
15
14
|
|
15
|
+
Or in your Rails 3 Gemfile
|
16
|
+
|
17
|
+
gem 'validates_email_format_of', :git => 'git://github.com/alexdunae/validates_email_format_of.git'
|
18
|
+
|
16
19
|
|
17
20
|
== Usage
|
18
21
|
|
@@ -61,12 +64,13 @@ The unit tests for this plugin use an in-memory sqlite3 database.
|
|
61
64
|
|
62
65
|
== Resources
|
63
66
|
|
64
|
-
*
|
65
|
-
* http://code.dunae.ca/validates_email_format_of.html
|
67
|
+
* https://github.com/alexdunae/validates_email_format_of
|
66
68
|
|
67
69
|
== Credits
|
68
70
|
|
69
|
-
Written by Alex Dunae (dunae.ca), 2006-
|
71
|
+
Written by Alex Dunae (dunae.ca), 2006-10.
|
72
|
+
|
73
|
+
Many thanks to the plugin's recent contributors: https://github.com/alexdunae/validates_email_format_of/contributors
|
70
74
|
|
71
75
|
Thanks to Francis Hwang (http://fhwang.net/) at Diversion Media for creating the 1.1 update.
|
72
76
|
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/rails/init'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/rails/init')
|
@@ -1,15 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ValidatesEmailFormatOf
|
2
3
|
require 'resolv'
|
3
4
|
|
4
5
|
LocalPartSpecialChars = Regexp.escape('!#$%&\'*-/=?+-^_`{|}~')
|
5
6
|
LocalPartUnquoted = '(([[:alnum:]' + LocalPartSpecialChars + ']+[\.\+]+))*[[:alnum:]' + LocalPartSpecialChars + '+]+'
|
6
7
|
LocalPartQuoted = '\"(([[:alnum:]' + LocalPartSpecialChars + '\.\+]*|(\\\\[\x00-\xFF]))*)\"'
|
7
|
-
Regex = Regexp.new('
|
8
|
+
Regex = Regexp.new('\A((' + LocalPartUnquoted + ')|(' + LocalPartQuoted + ')+)@(((\w+\-+[^_])|(\w+\.[a-z0-9-]*))*([a-z0-9-]{1,63})\.[a-z]{2,6}(?:\.[a-z]{2,6})?\Z)', Regexp::EXTENDED | Regexp::IGNORECASE, 'n')
|
8
9
|
|
9
10
|
def self.validate_email_domain(email)
|
10
11
|
domain = email.match(/\@(.+)/)[1]
|
11
12
|
Resolv::DNS.open do |dns|
|
12
|
-
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
|
13
|
+
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) + dns.getresources(domain, Resolv::DNS::Resource::IN::A)
|
13
14
|
end
|
14
15
|
@mx.size > 0 ? true : false
|
15
16
|
end
|
@@ -23,12 +24,14 @@ module ValidatesEmailFormatOf
|
|
23
24
|
# * <tt>mx_message</tt> - A custom error message when an MX record validation fails (default is: "is not routable.")
|
24
25
|
# * <tt>with</tt> The regex to use for validating the format of the email address (default is ValidatesEmailFormatOf::Regex)</tt>
|
25
26
|
def self.validate_email_format(email, options={})
|
26
|
-
default_options = { :message => 'does not appear to be a valid e-mail address',
|
27
|
+
default_options = { :message => I18n.t(:invalid_email_address, :scope => [:activerecord, :errors, :messages], :default => 'does not appear to be a valid e-mail address'),
|
27
28
|
:check_mx => false,
|
28
|
-
:mx_message => 'is not routable
|
29
|
+
:mx_message => I18n.t(:email_address_not_routable, :scope => [:activerecord, :errors, :messages], :default => 'is not routable'),
|
29
30
|
:with => ValidatesEmailFormatOf::Regex }
|
30
31
|
options.merge!(default_options) {|key, old, new| old} # merge the default options into the specified options, retaining all specified options
|
31
|
-
|
32
|
+
|
33
|
+
email.strip!
|
34
|
+
|
32
35
|
# local part max is 64 chars, domain part max is 255 chars
|
33
36
|
# TODO: should this decode escaped entities before counting?
|
34
37
|
begin
|
@@ -85,4 +88,4 @@ module ActiveRecord
|
|
85
88
|
end
|
86
89
|
end
|
87
90
|
end
|
88
|
-
end
|
91
|
+
end
|
data/test/database.yml
ADDED
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
-
RAILS_ROOT = File.dirname(__FILE__)
|
3
2
|
|
4
3
|
require 'rubygems'
|
5
4
|
require 'test/unit'
|
@@ -7,7 +6,6 @@ require 'active_record'
|
|
7
6
|
require 'active_record/fixtures'
|
8
7
|
require "#{File.dirname(__FILE__)}/../init"
|
9
8
|
|
10
|
-
|
11
9
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
12
10
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
13
11
|
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'plugin_test'])
|
@@ -22,7 +20,7 @@ else
|
|
22
20
|
end
|
23
21
|
|
24
22
|
TEST_CASE.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
25
|
-
|
23
|
+
$:.unshift(TEST_CASE.fixture_path)
|
26
24
|
|
27
25
|
class TEST_CASE #:nodoc:
|
28
26
|
def create_fixtures(*table_names)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
|
3
3
|
class ValidatesEmailFormatOfTest < TEST_CASE
|
4
|
-
fixtures :people
|
4
|
+
fixtures :people
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@valid_email = 'valid@example.com'
|
@@ -31,6 +31,10 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
31
31
|
'valid@example.mobi',
|
32
32
|
'valid@example.info',
|
33
33
|
'valid-@example.com',
|
34
|
+
# allow single character domain parts
|
35
|
+
'valid@mail.x.example.com',
|
36
|
+
'valid@x.com',
|
37
|
+
'valid@example.w-dash.sch.uk',
|
34
38
|
# from RFC 3696, page 6
|
35
39
|
'customer/department=shipping@example.com',
|
36
40
|
'$A12345@example.com',
|
@@ -62,6 +66,11 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
62
66
|
'invalid@example.c',
|
63
67
|
'invali d@example.com',
|
64
68
|
'invalidexample.com',
|
69
|
+
# should not allow special chars after a period in the domain
|
70
|
+
'local@sub.)domain.com',
|
71
|
+
'local@sub.#domain.com',
|
72
|
+
# one at a time
|
73
|
+
"foo@example.com\nexample@gmail.com",
|
65
74
|
'invalid@example.'].each do |email|
|
66
75
|
p = create_person(:email => email)
|
67
76
|
save_fails(p, email)
|
@@ -112,7 +121,11 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
112
121
|
def test_should_allow_custom_error_message
|
113
122
|
p = create_person(:email => @invalid_email)
|
114
123
|
save_fails(p)
|
115
|
-
|
124
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
125
|
+
assert_equal 'fails with custom message', p.errors[:email].first
|
126
|
+
else
|
127
|
+
assert_equal 'fails with custom message', p.errors.on(:email)
|
128
|
+
end
|
116
129
|
end
|
117
130
|
|
118
131
|
def test_should_allow_nil
|
@@ -120,14 +133,21 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
120
133
|
save_passes(p)
|
121
134
|
end
|
122
135
|
|
136
|
+
# TODO: find a future-proof way to check DNS records
|
123
137
|
def test_check_mx
|
124
138
|
pmx = MxRecord.new(:email => 'test@dunae.ca')
|
125
139
|
save_passes(pmx)
|
126
140
|
|
127
|
-
pmx = MxRecord.new(:email => 'test@
|
141
|
+
pmx = MxRecord.new(:email => 'test@somethingthathasntbeenregistered.com')
|
128
142
|
save_fails(pmx)
|
129
143
|
end
|
130
144
|
|
145
|
+
# TODO: find a future-proof way to check DNS records
|
146
|
+
def test_check_mx_fallback_to_a
|
147
|
+
pmx = MxRecord.new(:email => 'test@code.dunae.ca')
|
148
|
+
save_passes(pmx)
|
149
|
+
end
|
150
|
+
|
131
151
|
protected
|
132
152
|
def create_person(params)
|
133
153
|
Person.new(params)
|
@@ -136,12 +156,20 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
136
156
|
def save_passes(p, email = '')
|
137
157
|
assert p.valid?, " validating #{email}"
|
138
158
|
assert p.save
|
139
|
-
|
159
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
160
|
+
assert p.errors[:email].empty?
|
161
|
+
else
|
162
|
+
assert_nil p.errors.on(:email)
|
163
|
+
end
|
140
164
|
end
|
141
165
|
|
142
166
|
def save_fails(p, email = '')
|
143
167
|
assert !p.valid?, " validating #{email}"
|
144
168
|
assert !p.save
|
145
|
-
|
169
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
170
|
+
assert_equal 1, p.errors[:email].size
|
171
|
+
else
|
172
|
+
assert p.errors.on(:email)
|
173
|
+
end
|
146
174
|
end
|
147
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_email_format_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 4
|
8
|
+
- 2
|
9
|
+
version: 1.4.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Alex Dunae
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-11-16 00:00:00 -08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -24,15 +29,20 @@ extra_rdoc_files:
|
|
24
29
|
- CHANGELOG.rdoc
|
25
30
|
- MIT-LICENSE
|
26
31
|
files:
|
32
|
+
- MIT-LICENSE
|
27
33
|
- init.rb
|
28
34
|
- rakefile.rb
|
29
|
-
- lib/validates_email_format_of.rb
|
30
|
-
- rails/init.rb
|
31
|
-
- README.rdoc
|
32
35
|
- CHANGELOG.rdoc
|
33
|
-
-
|
36
|
+
- README.rdoc
|
37
|
+
- lib/validates_email_format_of.rb
|
38
|
+
- test/fixtures/person.rb
|
39
|
+
- test/schema.rb
|
40
|
+
- test/test_helper.rb
|
41
|
+
- test/validates_email_format_of_test.rb
|
42
|
+
- test/database.yml
|
43
|
+
- test/fixtures/people.yml
|
34
44
|
has_rdoc: true
|
35
|
-
homepage:
|
45
|
+
homepage: https://github.com/alexdunae/validates_email_format_of
|
36
46
|
licenses: []
|
37
47
|
|
38
48
|
post_install_message:
|
@@ -42,27 +52,32 @@ rdoc_options:
|
|
42
52
|
require_paths:
|
43
53
|
- lib
|
44
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
45
56
|
requirements:
|
46
57
|
- - ">="
|
47
58
|
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
48
61
|
version: "0"
|
49
|
-
version:
|
50
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
51
64
|
requirements:
|
52
65
|
- - ">="
|
53
66
|
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
54
69
|
version: "0"
|
55
|
-
version:
|
56
70
|
requirements: []
|
57
71
|
|
58
72
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.7
|
60
74
|
signing_key:
|
61
75
|
specification_version: 3
|
62
76
|
summary: Validate e-mail addresses against RFC 2822 and RFC 3696.
|
63
77
|
test_files:
|
64
|
-
- test/validates_email_format_of_test.rb
|
65
|
-
- test/test_helper.rb
|
66
|
-
- test/schema.rb
|
67
78
|
- test/fixtures/person.rb
|
79
|
+
- test/schema.rb
|
80
|
+
- test/test_helper.rb
|
81
|
+
- test/validates_email_format_of_test.rb
|
82
|
+
- test/database.yml
|
68
83
|
- test/fixtures/people.yml
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'validates_email_format_of'
|