valid_email2 3.1.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -1
- data/lib/valid_email2/address.rb +32 -26
- data/lib/valid_email2/email_validator.rb +4 -0
- data/lib/valid_email2/version.rb +1 -1
- data/spec/valid_email2_spec.rb +27 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc608e090f5de38c7126888581eaad8610393e05e5d93a42494a6b35f44db4e
|
4
|
+
data.tar.gz: b95740599e8cad05d701563f613561e17a420fcc69e98afa7edcfcced19afdd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e355481ab31a6733e037a0c053e894634895d67e1aa078480e74da6304a644eb668f8415da71815cf2f58d35d4279383bb9622d510898cde3c48efc51771eb
|
7
|
+
data.tar.gz: e957769daec7de10bc8cd64c998a7bd678cc3e086446b280a4013e0a43ddf247692e78fc26f14e2a5eb1044082b44445d71f36cd722a7ff487b34c8af0b9235a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Version 3.1.3
|
2
|
+
* Disallow `/` in addresses https://github.com/micke/valid_email2/pull/142
|
3
|
+
* Add option to only validate that domain is not in list of disposable emails https://github.com/micke/valid_email2/pull/141
|
4
|
+
|
1
5
|
## Version 3.1.2
|
2
6
|
* Disallow ` ` in addresses https://github.com/micke/valid_email2/pull/139
|
3
7
|
|
data/README.md
CHANGED
@@ -48,11 +48,16 @@ To validate that the domain has a MX record:
|
|
48
48
|
validates :email, 'valid_email_2/email': { mx: true }
|
49
49
|
```
|
50
50
|
|
51
|
-
To validate that the domain is not a disposable email:
|
51
|
+
To validate that the domain is not a disposable email (checks domain and MX server):
|
52
52
|
```ruby
|
53
53
|
validates :email, 'valid_email_2/email': { disposable: true }
|
54
54
|
```
|
55
55
|
|
56
|
+
To validate that the domain is not a disposable email (checks domain only, does not check MX server):
|
57
|
+
```ruby
|
58
|
+
validates :email, 'valid_email_2/email': { disposable_domain: true }
|
59
|
+
```
|
60
|
+
|
56
61
|
To validate that the domain is not a disposable email or a disposable email but whitelisted (under config/whitelisted_email_domains.yml):
|
57
62
|
```ruby
|
58
63
|
validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
|
data/lib/valid_email2/address.rb
CHANGED
@@ -6,7 +6,7 @@ module ValidEmail2
|
|
6
6
|
class Address
|
7
7
|
attr_accessor :address
|
8
8
|
|
9
|
-
PROHIBITED_DOMAIN_CHARACTERS_REGEX = /[+!_
|
9
|
+
PROHIBITED_DOMAIN_CHARACTERS_REGEX = /[+!_\/\s]/
|
10
10
|
DEFAULT_RECIPIENT_DELIMITER = '+'.freeze
|
11
11
|
|
12
12
|
def initialize(address)
|
@@ -23,26 +23,28 @@ module ValidEmail2
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def valid?
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
domain
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
26
|
+
@valid ||= begin
|
27
|
+
return false if @parse_error
|
28
|
+
|
29
|
+
if address.domain && address.address == @raw_address
|
30
|
+
domain = address.domain
|
31
|
+
|
32
|
+
domain !~ PROHIBITED_DOMAIN_CHARACTERS_REGEX &&
|
33
|
+
# Domain needs to have at least one dot
|
34
|
+
domain =~ /\./ &&
|
35
|
+
# Domain may not have two consecutive dots
|
36
|
+
domain !~ /\.{2,}/ &&
|
37
|
+
# Domain may not start with a dot
|
38
|
+
domain !~ /^\./ &&
|
39
|
+
# Domain may not start with a dash
|
40
|
+
domain !~ /^-/ &&
|
41
|
+
# Domain name may not end with a dash
|
42
|
+
domain !~ /-\./ &&
|
43
|
+
# Address may not contain a dot directly before @
|
44
|
+
address.address !~ /\.@/
|
45
|
+
else
|
46
|
+
false
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -51,11 +53,15 @@ module ValidEmail2
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def disposable?
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
disposable_domain? || disposable_mx_server?
|
57
|
+
end
|
58
|
+
|
59
|
+
def disposable_domain?
|
60
|
+
valid? && domain_is_in?(ValidEmail2.disposable_emails)
|
61
|
+
end
|
62
|
+
|
63
|
+
def disposable_mx_server?
|
64
|
+
valid? && mx_server_is_in?(ValidEmail2.disposable_emails)
|
59
65
|
end
|
60
66
|
|
61
67
|
def whitelisted?
|
@@ -24,6 +24,10 @@ module ValidEmail2
|
|
24
24
|
error(record, attribute) && return if address.disposable?
|
25
25
|
end
|
26
26
|
|
27
|
+
if options[:disposable_domain]
|
28
|
+
error(record, attribute) && return if address.disposable_domain?
|
29
|
+
end
|
30
|
+
|
27
31
|
if options[:disposable_with_whitelist]
|
28
32
|
error(record, attribute) && return if address.disposable? && !address.whitelisted?
|
29
33
|
end
|
data/lib/valid_email2/version.rb
CHANGED
data/spec/valid_email2_spec.rb
CHANGED
@@ -18,6 +18,10 @@ class TestUserDisallowDisposable < TestModel
|
|
18
18
|
validates :email, 'valid_email_2/email': { disposable: true }
|
19
19
|
end
|
20
20
|
|
21
|
+
class TestUserDisallowDisposableDomain < TestModel
|
22
|
+
validates :email, 'valid_email_2/email': { disposable_domain: true }
|
23
|
+
end
|
24
|
+
|
21
25
|
class TestUserDisallowDisposableWithWhitelist < TestModel
|
22
26
|
validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
|
23
27
|
end
|
@@ -89,6 +93,11 @@ describe ValidEmail2 do
|
|
89
93
|
expect(user.valid?).to be_falsy
|
90
94
|
end
|
91
95
|
|
96
|
+
it "is invalid if the domain contains a forward slash" do
|
97
|
+
user = TestUser.new(email: "user@gm/ail.com")
|
98
|
+
expect(user.valid?).to be_falsy
|
99
|
+
end
|
100
|
+
|
92
101
|
it "is invalid if the domain begins with a dash" do
|
93
102
|
user = TestUser.new(email: "foo@-gmail.com")
|
94
103
|
expect(user.valid?).to be_falsy
|
@@ -111,19 +120,26 @@ describe ValidEmail2 do
|
|
111
120
|
expect(user.valid?).to be_truthy
|
112
121
|
end
|
113
122
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
123
|
+
context "with disposable domain" do
|
124
|
+
it "is invalid with disposable domain" do
|
125
|
+
user = TestUserDisallowDisposable.new(email: "foo@#{disposable_domain}")
|
126
|
+
expect(user.valid?).to be_falsey
|
127
|
+
end
|
118
128
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
129
|
+
it "is invalid with disposable domain even without mx server check" do
|
130
|
+
user = TestUserDisallowDisposableDomain.new(email: "foo@#{disposable_domain}")
|
131
|
+
expect(user.valid?).to be_falsey
|
132
|
+
end
|
123
133
|
|
124
|
-
|
125
|
-
|
126
|
-
|
134
|
+
it "is invalid if the domain is a subdomain of a disposable domain" do
|
135
|
+
user = TestUserDisallowDisposable.new(email: "foo@bar.#{disposable_domain}")
|
136
|
+
expect(user.valid?).to be_falsey
|
137
|
+
end
|
138
|
+
|
139
|
+
it "allows example.com" do
|
140
|
+
user = TestUserDisallowDisposable.new(email: "foo@example.com")
|
141
|
+
expect(user.valid?).to be_truthy
|
142
|
+
end
|
127
143
|
end
|
128
144
|
|
129
145
|
context "with domain that is not disposable but it's mx server is disposable" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_email2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micke Lisinge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|