valid_email2 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71c14200d42afbdf47d3222f443c72f81dd23af157f32baebbcc607d2ef09959
4
- data.tar.gz: 67e841c534a03d363b118bc50026dcc54ee1550478a98d92e885d53c40905ffe
3
+ metadata.gz: 85903e3f9f5d0e8222dcc7768e15632eecf4a6008e8a43c2d88549cfa9a140ae
4
+ data.tar.gz: 2519e54f15012418caa00608301ff19f91640ecf63e9cf88c586afa2d1a0d2d2
5
5
  SHA512:
6
- metadata.gz: 27e0b370d3fc4fa2fb1530e931c9f06156c88045f9b55a4b9e038d521460b34ac4dc8b81f6194ea649477cb4169774cfe3b7a9ad15e06447f472b0742700433e
7
- data.tar.gz: d160ab3de4196dc830e26aedab650c9839520b9aadccb9e6153305eb42ad796929cab5a209aef3ce869e1a801171b7de45fdc23d3e5ac6004436ad7e31a2a6ef
6
+ metadata.gz: 811d82babbd7ad076fc077d4dea52074ecf6591926ed6b37b4f6595b614bc46eeacfd944db95ebc577a6cfb36d858009a051eed67e87fa5ce3f06b63c576c8b6
7
+ data.tar.gz: 653fe9f637840019997480853e5784e4fba055f4d579bce8af3b30e631da8fe86a5074e00564d72444f7b4a1cd0f4d7d829d9928e7c3962d1b612b595cc16545
@@ -1,3 +1,8 @@
1
+ ## Version 3.5.0
2
+ * Disallow emails starting with a dot https://github.com/micke/valid_email2/pull/170
3
+ * Add option to whitelist domains from MX check https://github.com/micke/valid_email2/pull/167
4
+ * Remove false positives
5
+
1
6
  ## Version 3.4.0
2
7
  * Disallow consecutive dots https://github.com/micke/valid_email2/pull/163
3
8
  * Add andyes.net https://github.com/micke/valid_email2/pull/162
data/README.md CHANGED
@@ -58,11 +58,17 @@ To validate that the domain is not a disposable email (checks domain only, does
58
58
  validates :email, 'valid_email_2/email': { disposable_domain: true }
59
59
  ```
60
60
 
61
- To validate that the domain is not a disposable email or a disposable email but whitelisted (under config/whitelisted_email_domains.yml):
61
+ To validate that the domain is not a disposable email or a disposable email (checks domain and MX server) but whitelisted (under config/whitelisted_email_domains.yml):
62
62
  ```ruby
63
63
  validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
64
64
  ```
65
65
 
66
+ To validate that the domain is not a disposable email or a disposable email (checks domain only, does not check MX server) but whitelisted (under config/whitelisted_email_domains.yml):
67
+
68
+ ```ruby
69
+ validates :email, 'valid_email_2/email': { disposable_domain_with_whitelist: true }
70
+ ```
71
+
66
72
  To validate that the domain is not blacklisted (under config/blacklisted_email_domains.yml):
67
73
  ```ruby
68
74
  validates :email, 'valid_email_2/email': { blacklist: true }
@@ -12324,7 +12324,6 @@ gd6ubc0xilchpozgpg.gq
12324
12324
  gd6ubc0xilchpozgpg.ml
12325
12325
  gd6ubc0xilchpozgpg.tk
12326
12326
  gdb.armageddon.org
12327
- gdf.it
12328
12327
  gdfretertwer.com
12329
12328
  gdmail.top
12330
12329
  gdradr.com
@@ -31027,7 +31026,6 @@ voyagebirmanie.net
31027
31026
  voyancegratuite10min.com
31028
31027
  voyeurseite.info
31029
31028
  vozmivtop.ru
31030
- vp.com
31031
31029
  vp.ycare.de
31032
31030
  vpanel.ru
31033
31031
  vpc608a0.pl
@@ -33700,4 +33698,4 @@ zzv2bfja5.pl
33700
33698
  zzz.co
33701
33699
  zzz.com
33702
33700
  zzzmail.pl
33703
- zzzzzzzzzzzzz.com
33701
+ zzzzzzzzzzzzz.com
@@ -46,7 +46,8 @@ module ValidEmail2
46
46
  !domain.start_with?('-') &&
47
47
  !domain.include?('-.') &&
48
48
  !address.local.include?('..') &&
49
- !address.local.end_with?('.')
49
+ !address.local.end_with?('.') &&
50
+ !address.local.start_with?('.')
50
51
  else
51
52
  false
52
53
  end
@@ -37,6 +37,10 @@ module ValidEmail2
37
37
  error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.whitelisted? }
38
38
  end
39
39
 
40
+ if options[:disposable_domain_with_whitelist]
41
+ error(record, attribute) && return if addresses.any? { |address| address.disposable_domain? && !address.whitelisted? }
42
+ end
43
+
40
44
  if options[:blacklist]
41
45
  error(record, attribute) && return if addresses.any?(&:blacklisted?)
42
46
  end
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "3.4.0"
2
+ VERSION = "3.5.0"
3
3
  end
@@ -31,6 +31,10 @@ class TestUserDisallowDisposableWithWhitelist < TestModel
31
31
  validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
32
32
  end
33
33
 
34
+ class TestUserDisallowDisposableDomainWithWhitelist < TestModel
35
+ validates :email, 'valid_email_2/email': { disposable_domain_with_whitelist: true }
36
+ end
37
+
34
38
  class TestUserDisallowBlacklisted < TestModel
35
39
  validates :email, 'valid_email_2/email': { blacklist: true }
36
40
  end
@@ -92,6 +96,16 @@ describe ValidEmail2 do
92
96
  expect(user.valid?).to be_falsey
93
97
  end
94
98
 
99
+ it "is invalid if the address starts with a dot" do
100
+ user = TestUser.new(email: ".foo@bar.com")
101
+ expect(user.valid?).to be_falsey
102
+ end
103
+
104
+ it "is invalid if the local part of the address ends with a dot" do
105
+ user = TestUser.new(email: "foo.@bar.com")
106
+ expect(user.valid?).to be_falsey
107
+ end
108
+
95
109
  it "is invalid if the email contains emoticons" do
96
110
  user = TestUser.new(email: "foo🙈@gmail.com")
97
111
  expect(user.valid?).to be_falsy
@@ -170,8 +184,18 @@ describe ValidEmail2 do
170
184
  let(:whitelist_domain) { disposable_domain }
171
185
  let(:whitelist_file_path) { "config/whitelisted_email_domains.yml" }
172
186
 
187
+ # Some of the specs below need to explictly set the whitelist var or it
188
+ # may be cached to an empty set
189
+ def set_whitelist
190
+ ValidEmail2.instance_variable_set(
191
+ :@whitelist,
192
+ ValidEmail2.send(:load_if_exists, ValidEmail2::WHITELIST_FILE)
193
+ )
194
+ end
195
+
173
196
  after do
174
197
  FileUtils.rm(whitelist_file_path, force: true)
198
+ set_whitelist
175
199
  end
176
200
 
177
201
  it "is invalid if the domain is disposable and not in the whitelist" do
@@ -181,9 +205,22 @@ describe ValidEmail2 do
181
205
 
182
206
  it "is valid if the domain is disposable but in the whitelist" do
183
207
  File.open(whitelist_file_path, "w") { |f| f.write [whitelist_domain].to_yaml }
208
+ set_whitelist
184
209
  user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{whitelist_domain}")
210
+ expect(user.valid?).to be_truthy
211
+ end
212
+
213
+ it "is invalid if the domain is a disposable_domain and not in the whitelist" do
214
+ user = TestUserDisallowDisposableDomainWithWhitelist.new(email: "foo@#{whitelist_domain}")
185
215
  expect(user.valid?).to be_falsey
186
216
  end
217
+
218
+ it "is valid if the domain is a disposable_domain but in the whitelist" do
219
+ File.open(whitelist_file_path, "w") { |f| f.write [whitelist_domain].to_yaml }
220
+ set_whitelist
221
+ user = TestUserDisallowDisposableDomainWithWhitelist.new(email: "foo@#{whitelist_domain}")
222
+ expect(user.valid?).to be_truthy
223
+ end
187
224
  end
188
225
  end
189
226
 
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.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micke Lisinge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler