validates_email_format_of 1.4.3 → 1.4.5
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 +6 -1
- data/lib/validates_email_format_of.rb +9 -4
- data/test/validates_email_format_of_test.rb +8 -1
- metadata +3 -6
data/CHANGELOG.rdoc
CHANGED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -55,6 +55,11 @@ e-mail address or an array of error messages for invalid addresses.
|
|
55
55
|
proc or string should return or evaluate to a true or false value.
|
56
56
|
:unless
|
57
57
|
See :if option.
|
58
|
+
:local_length
|
59
|
+
Maximum number of characters allowed in the local part (default is 64)
|
60
|
+
:domain_length
|
61
|
+
Maximum number of characters allowed in the domain part (default is 255)
|
62
|
+
|
58
63
|
|
59
64
|
== Testing
|
60
65
|
|
@@ -68,7 +73,7 @@ The unit tests for this plugin use an in-memory sqlite3 database.
|
|
68
73
|
|
69
74
|
== Credits
|
70
75
|
|
71
|
-
Written by Alex Dunae (dunae.ca), 2006-
|
76
|
+
Written by Alex Dunae (dunae.ca), 2006-11.
|
72
77
|
|
73
78
|
Many thanks to the plugin's recent contributors: https://github.com/alexdunae/validates_email_format_of/contributors
|
74
79
|
|
@@ -3,8 +3,8 @@ module ValidatesEmailFormatOf
|
|
3
3
|
require 'resolv'
|
4
4
|
|
5
5
|
LocalPartSpecialChars = Regexp.escape('!#$%&\'*-/=?+-^_`{|}~')
|
6
|
-
LocalPartUnquoted = '([[:alnum:]' + LocalPartSpecialChars + ']+[
|
7
|
-
LocalPartQuoted = '\"([[:alnum:]' + LocalPartSpecialChars + '
|
6
|
+
LocalPartUnquoted = '([[:alnum:]' + LocalPartSpecialChars + ']+[\.]+)*[[:alnum:]' + LocalPartSpecialChars + '+]+'
|
7
|
+
LocalPartQuoted = '\"([[:alnum:]' + LocalPartSpecialChars + '\.]|\\\\[\x00-\xFF])*\"'
|
8
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')
|
9
9
|
|
10
10
|
def self.validate_email_domain(email)
|
@@ -23,11 +23,16 @@ module ValidatesEmailFormatOf
|
|
23
23
|
# * <tt>check_mx</tt> - Check for MX records (default is false)
|
24
24
|
# * <tt>mx_message</tt> - A custom error message when an MX record validation fails (default is: "is not routable.")
|
25
25
|
# * <tt>with</tt> The regex to use for validating the format of the email address (default is ValidatesEmailFormatOf::Regex)</tt>
|
26
|
+
# * <tt>local_length</tt> Maximum number of characters allowed in the local part (default is 64)
|
27
|
+
# * <tt>domain_length</tt> Maximum number of characters allowed in the domain part (default is 255)
|
26
28
|
def self.validate_email_format(email, options={})
|
27
29
|
default_options = { :message => I18n.t(:invalid_email_address, :scope => [:activerecord, :errors, :messages], :default => 'does not appear to be a valid e-mail address'),
|
28
30
|
:check_mx => false,
|
29
31
|
:mx_message => I18n.t(:email_address_not_routable, :scope => [:activerecord, :errors, :messages], :default => 'is not routable'),
|
30
|
-
:with => ValidatesEmailFormatOf::Regex
|
32
|
+
:with => ValidatesEmailFormatOf::Regex ,
|
33
|
+
:domain_length => 255,
|
34
|
+
:local_length => 64
|
35
|
+
}
|
31
36
|
options.merge!(default_options) {|key, old, new| old} # merge the default options into the specified options, retaining all specified options
|
32
37
|
|
33
38
|
email.strip!
|
@@ -40,7 +45,7 @@ module ValidatesEmailFormatOf
|
|
40
45
|
return [ options[:message] ]
|
41
46
|
end
|
42
47
|
|
43
|
-
unless email =~ options[:with] and not email =~ /\.\./ and domain.length <=
|
48
|
+
unless email =~ options[:with] and not email =~ /\.\./ and domain.length <= options[:domain_length] and local.length <= options[:local_length]
|
44
49
|
return [ options[:message] ]
|
45
50
|
end
|
46
51
|
|
@@ -66,7 +66,9 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
66
66
|
'invalid@example.c',
|
67
67
|
'invali d@example.com',
|
68
68
|
# unclosed quote
|
69
|
-
|
69
|
+
"\"a-17180061943-10618354-1993365053",
|
70
|
+
# too many special chars used to cause the regexp to hang
|
71
|
+
"-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++@foo",
|
70
72
|
'invalidexample.com',
|
71
73
|
# should not allow special chars after a period in the domain
|
72
74
|
'local@sub.)domain.com',
|
@@ -110,6 +112,11 @@ class ValidatesEmailFormatOfTest < TEST_CASE
|
|
110
112
|
save_fails(p, email)
|
111
113
|
end
|
112
114
|
end
|
115
|
+
|
116
|
+
def test_overriding_length_checks
|
117
|
+
assert_not_nil ValidatesEmailFormatOf::validate_email_format('valid@example.com', :local_length => 1)
|
118
|
+
assert_not_nil ValidatesEmailFormatOf::validate_email_format('valid@example.com', :domain_length => 1)
|
119
|
+
end
|
113
120
|
|
114
121
|
def test_should_respect_validate_on_option
|
115
122
|
p = create_person(:email => @valid_email)
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_email_format_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 1
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
8
|
+
- 5
|
9
|
+
version: 1.4.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Alex Dunae
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-01-20 00:00:00 -08:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
@@ -57,7 +56,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
56
|
requirements:
|
58
57
|
- - ">="
|
59
58
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
59
|
segments:
|
62
60
|
- 0
|
63
61
|
version: "0"
|
@@ -66,7 +64,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
64
|
requirements:
|
67
65
|
- - ">="
|
68
66
|
- !ruby/object:Gem::Version
|
69
|
-
hash: 3
|
70
67
|
segments:
|
71
68
|
- 0
|
72
69
|
version: "0"
|