email_validator 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
@@ -7,26 +7,30 @@ PATH
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.0.9)
11
- activesupport (= 3.0.9)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.5.0)
14
- activesupport (3.0.9)
15
- builder (2.1.2)
16
- diff-lcs (1.1.2)
17
- i18n (0.5.0)
18
- rspec (2.6.0)
19
- rspec-core (~> 2.6.0)
20
- rspec-expectations (~> 2.6.0)
21
- rspec-mocks (~> 2.6.0)
22
- rspec-core (2.6.4)
23
- rspec-expectations (2.6.0)
10
+ activemodel (3.1.3)
11
+ activesupport (= 3.1.3)
12
+ builder (~> 3.0.0)
13
+ i18n (~> 0.6)
14
+ activesupport (3.1.3)
15
+ multi_json (~> 1.0)
16
+ builder (3.0.0)
17
+ diff-lcs (1.1.3)
18
+ i18n (0.6.0)
19
+ multi_json (1.0.4)
20
+ rake (0.9.2.2)
21
+ rspec (2.7.0)
22
+ rspec-core (~> 2.7.0)
23
+ rspec-expectations (~> 2.7.0)
24
+ rspec-mocks (~> 2.7.0)
25
+ rspec-core (2.7.1)
26
+ rspec-expectations (2.7.0)
24
27
  diff-lcs (~> 1.1.2)
25
- rspec-mocks (2.6.0)
28
+ rspec-mocks (2.7.0)
26
29
 
27
30
  PLATFORMS
28
31
  ruby
29
32
 
30
33
  DEPENDENCIES
31
34
  email_validator!
35
+ rake
32
36
  rspec
@@ -1,3 +1,5 @@
1
+ {<img src="https://secure.travis-ci.org/balexand/email_validator.png" />}[http://travis-ci.org/balexand/email_validator]
2
+
1
3
  == Usage
2
4
 
3
5
  Add to your Gemfile:
@@ -12,7 +14,18 @@ Then add the following to your model:
12
14
 
13
15
  validates :my_email_attribute, :email => true
14
16
 
17
+ == Strict mode
18
+
19
+ In order to have stricter validation (according to http://www.remote.org/jochen/mail/info/chars.html) enable strict mode. You can do this globally by adding the following to your Gemfile:
20
+
21
+ gem 'email_validator', :require => 'email_validator/strict'
22
+
23
+ Or you can do this in a specific `validates` call:
24
+
25
+ validates :my_email_attribute, :email => {:strict_mode => true}
26
+
15
27
  == Credit
16
28
 
17
29
  Based on http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3
18
30
  Regular Expression based on http://fightingforalostcause.net/misc/2006/compare-email-regex.php tests.
31
+
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'bundler'
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
3
+ begin
4
+ require 'rdoc/task'
5
+ rescue LoadError
6
+ require 'rake/rdoctask' # deprecated in Ruby 1.9.3 but needed for Ruby 1.8.7 and JRuby
7
+ end
4
8
  require 'rspec/core/rake_task'
5
9
 
6
10
  Bundler::GemHelper.install_tasks
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{email_validator}
3
- s.version = "1.2.4"
3
+ s.version = "1.3.0"
4
4
  s.authors = ["Brian Alexander"]
5
5
  s.date = %q{2011-07-23}
6
6
  s.description = %q{An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator}
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.require_paths = %w(lib)
16
16
  s.summary = %q{An email validator for Rails 3.}
17
17
  s.add_dependency("activemodel", ">= 0")
18
+ s.add_development_dependency("rake")
18
19
  s.add_development_dependency("rspec", ">= 0")
19
20
  end
20
21
 
@@ -1,7 +1,15 @@
1
1
  # Based on work from http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/
2
2
  class EmailValidator < ActiveModel::EachValidator
3
+ @@default_options = {}
4
+
5
+ def self.default_options
6
+ @@default_options
7
+ end
8
+
3
9
  def validate_each(record, attribute, value)
4
- unless value =~ /^\s*([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*$/i
10
+ options = @@default_options.merge(self.options)
11
+ name_validation = options[:strict_mode] ? "-a-z0-9+._" : "^@\\s"
12
+ unless value =~ /^\s*([#{name_validation}]{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*$/i
5
13
  record.errors.add(attribute, options[:message] || :invalid)
6
14
  end
7
15
  end
@@ -0,0 +1,5 @@
1
+ # require this file to enable :strict_mode by default
2
+
3
+ require 'email_validator'
4
+
5
+ EmailValidator::default_options[:strict_mode] = true
@@ -4,6 +4,10 @@ class TestUser < TestModel
4
4
  validates :email, :email => true
5
5
  end
6
6
 
7
+ class StrictUser < TestModel
8
+ validates :email, :email => {:strict_mode => true}
9
+ end
10
+
7
11
  class TestUserAllowsNil < TestModel
8
12
  validates :email, :email => {:allow_nil => true}
9
13
  end
@@ -20,18 +24,14 @@ describe EmailValidator do
20
24
 
21
25
  describe "validation" do
22
26
  context "given the valid emails" do
23
- [ "user@example.com",
27
+ [
28
+ "a+b@plus-in-local.com",
29
+ "a_b@underscore-in-local.com",
30
+ "user@example.com",
24
31
  " user@example.com ",
25
32
  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org",
26
33
  "01234567890@numbers-in-local.net",
27
- "&'*+-./=?^_{}~@other-valid-characters-in-local.net",
28
- "mixed-1234-in-{+^}-local@sld.net",
29
34
  "a@single-character-in-local.org",
30
- "\"quoted\"@sld.com",
31
- "\"\\e\\s\\c\\a\\p\\e\\d\"@sld.com",
32
- # "\"quoted-at-sign@sld.org\"@sld.com",
33
- "\"escaped\\\"quote\"@sld.com",
34
- "\"back\\slash\"@sld.com",
35
35
  "one-character-third-level@a.example.com",
36
36
  "single-character-in-sld@x.org",
37
37
  "local@dash-in-sld.com",
@@ -43,9 +43,7 @@ describe EmailValidator do
43
43
  "country-code-tld@sld.uk",
44
44
  "country-code-tld@sld.rw",
45
45
  "local@sld.newTLD",
46
- # "punycode-numbers-in-tld@sld.xn--3e0b707e",
47
46
  "local@sub.domains.com",
48
- # "bracketed-IP-instead-of-domain@[127.0.0.1]",
49
47
  "aaa@bbb.co.jp",
50
48
  "nigel.worthington@big.co.uk",
51
49
  "f@c.com",
@@ -56,44 +54,68 @@ describe EmailValidator do
56
54
  TestUser.new(:email => email).should be_valid
57
55
  end
58
56
 
57
+ it "#{email.inspect} should be valid in strict_mode" do
58
+ StrictUser.new(:email => email).should be_valid
59
+ end
60
+
59
61
  end
60
62
 
61
63
  end
62
64
 
63
65
  context "given the invalid emails" do
64
- [ "",
66
+ [
67
+ "",
65
68
  "f@s",
66
69
  "f@s.c",
67
70
  "@bar.com",
68
71
  "test@example.com@example.com",
69
72
  "test@",
70
73
  "@missing-local.org",
74
+ "a b@space-in-local.com",
71
75
  "! \#$%\`|@invalid-characters-in-local.org",
72
- # "(),:;\`|@more-invalid-characters-in-local.org",
73
76
  "<>@[]\`|@even-more-invalid-characters-in-local.org",
74
- # ".local-starts-with-dot@sld.com",
75
- # "local-ends-with-dot.@sld.com",
76
- # "two..consecutive-dots@sld.com",
77
- # "partially.\"quoted\"@sld.com",
78
- # "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net",
79
77
  "missing-sld@.com",
80
- # "sld-starts-with-dashsh@-sld.com",
81
- # "sld-ends-with-dash@sld-.com",
82
78
  "invalid-characters-in-sld@! \"\#$%(),/;<>_[]\`|.org",
83
79
  "missing-dot-before-tld@com",
84
80
  "missing-tld@sld.",
85
81
  " ",
86
- # "the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-255-characters-exactly-so-it-should-be-invalid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-blah-blah-blah-blah.org",
87
82
  "missing-at-sign.net",
88
83
  "unbracketed-IP@127.0.0.1",
89
84
  "invalid-ip@127.0.0.1.26",
90
85
  "another-invalid-ip@127.0.0.256",
91
- "IP-and-port@127.0.0.1:25" ].each do |email|
86
+ "IP-and-port@127.0.0.1:25",
87
+ "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net"
88
+ ].each do |email|
92
89
 
93
90
  it "#{email.inspect} should not be valid" do
94
91
  TestUser.new(:email => email).should_not be_valid
95
92
  end
96
93
 
94
+ it "#{email.inspect} should not be valid in strict_mode" do
95
+ StrictUser.new(:email => email).should_not be_valid
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ context "given the emails that should be invalid in strict_mode but valid in normal mode" do
102
+ [
103
+ "hans,peter@example.com",
104
+ "hans(peter@example.com",
105
+ "hans)peter@example.com",
106
+ "partially.\"quoted\"@sld.com",
107
+ "&'*+-./=?^_{}~@other-valid-characters-in-local.net",
108
+ "mixed-1234-in-{+^}-local@sld.net"
109
+ ].each do |email|
110
+
111
+ it "#{email.inspect} should be valid" do
112
+ TestUser.new(:email => email).should be_valid
113
+ end
114
+
115
+ it "#{email.inspect} should not be valid in strict_mode" do
116
+ StrictUser.new(:email => email).should_not be_valid
117
+ end
118
+
97
119
  end
98
120
  end
99
121
  end
@@ -131,4 +153,14 @@ describe EmailValidator do
131
153
  TestUserAllowsNilFalse.new(:email => nil).should_not be_valid
132
154
  end
133
155
  end
134
- end
156
+
157
+ describe "default_options" do
158
+ context "when 'email_validator/strict' has been required" do
159
+ before { require 'email_validator/strict' }
160
+
161
+ it "should validate using strict mode" do
162
+ TestUser.new(:email => "&'*+-./=?^_{}~@other-valid-characters-in-local.net").should_not be_valid
163
+ end
164
+ end
165
+ end
166
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-23 00:00:00.000000000 -07:00
13
- default_executable:
12
+ date: 2011-07-23 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activemodel
17
- requirement: &70129050140280 !ruby/object:Gem::Requirement
16
+ requirement: &70351238018900 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,21 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *70129050140280
24
+ version_requirements: *70351238018900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70351238018180 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70351238018180
26
36
  - !ruby/object:Gem::Dependency
27
37
  name: rspec
28
- requirement: &70129050139800 !ruby/object:Gem::Requirement
38
+ requirement: &70351238017440 !ruby/object:Gem::Requirement
29
39
  none: false
30
40
  requirements:
31
41
  - - ! '>='
@@ -33,7 +43,7 @@ dependencies:
33
43
  version: '0'
34
44
  type: :development
35
45
  prerelease: false
36
- version_requirements: *70129050139800
46
+ version_requirements: *70351238017440
37
47
  description: ! 'An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator'
38
48
  email: balexand@gmail.com
39
49
  executables: []
@@ -44,6 +54,7 @@ extra_rdoc_files:
44
54
  files:
45
55
  - .document
46
56
  - .gitignore
57
+ - .travis.yml
47
58
  - Gemfile
48
59
  - Gemfile.lock
49
60
  - LICENSE
@@ -51,9 +62,9 @@ files:
51
62
  - Rakefile
52
63
  - email_validator.gemspec
53
64
  - lib/email_validator.rb
65
+ - lib/email_validator/strict.rb
54
66
  - spec/email_validator_spec.rb
55
67
  - spec/spec_helper.rb
56
- has_rdoc: true
57
68
  homepage: http://github.com/balexand/email_validator
58
69
  licenses: []
59
70
  post_install_message:
@@ -74,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
85
  version: '0'
75
86
  requirements: []
76
87
  rubyforge_project:
77
- rubygems_version: 1.6.2
88
+ rubygems_version: 1.8.10
78
89
  signing_key:
79
90
  specification_version: 3
80
91
  summary: An email validator for Rails 3.