valid_email2 3.0.5 → 3.1.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: 3579df33c2e2b6f61deb537f9b53429419c8e3eeee9c2f7983c73587b7831d4e
4
- data.tar.gz: a8438e557f74f5ca789e1d45de65a2e7202232f9b69b34d4639946f55eb504bc
3
+ metadata.gz: 6b1b27babaa4cb566d2b63dc25f726f534ad05fb9364d21c52c44c775ce12218
4
+ data.tar.gz: 735df3dc625cebce4bda35547a4d3b6e8e558fc2133872c8b678e51a4891c073
5
5
  SHA512:
6
- metadata.gz: f1a23d4278a946a56bb105839a3b4b6e4cc87830d160d7ca7ed6c82e3ae28638be3d6eb0868af73862cd0819099f36163eb42c5496ffd066c16cd547271fd907
7
- data.tar.gz: 9c513901af108ac87275cb162eb832be8205c095b2da12486c67f479e08fdc5c113129c7dc2432058c2a4e88c487ad70fee44af87f2fa27f1cb33ff3fbb4abf8
6
+ metadata.gz: f4d6da63e2f4f1894605a1b83f0c92300d8fe3d8a558d09f670d890d38ef3efbf3f59dfdd49f1bda9696ddad73c0ee5b9fd33ca742f7293524cb29e83c96b57f
7
+ data.tar.gz: e74ea532d0510bdd0c9c8ddcc53e88aebc384d3ea4bafe475c28a754518f90103873c814134acb2cc942720a5f889ff349a142b5164e842d81bc67a08816ce1a
@@ -1,3 +1,6 @@
1
+ ## Version 3.1.0
2
+ * Performance improvements https://github.com/micke/valid_email2/pull/137
3
+
1
4
  ## Version 3.0.5
2
5
  * Addresses with a dot before the @ is not valid https://github.com/micke/valid_email2/pull/136
3
6
 
@@ -7,14 +7,14 @@ module ValidEmail2
7
7
  WHITELIST_FILE = "config/whitelisted_email_domains.yml"
8
8
 
9
9
  def self.disposable_emails
10
- @disposable_emails ||= YAML.load_file(
10
+ @disposable_emails ||= load_file(
11
11
  File.expand_path('../config/disposable_email_domains.yml', __dir__)
12
12
  )
13
13
  end
14
14
 
15
15
  def self.blacklist
16
16
  @blacklist ||= if File.exist?(BLACKLIST_FILE)
17
- YAML.load_file(File.expand_path(BLACKLIST_FILE))
17
+ load_file(File.expand_path(BLACKLIST_FILE))
18
18
  else
19
19
  []
20
20
  end
@@ -22,9 +22,13 @@ module ValidEmail2
22
22
 
23
23
  def self.whitelist
24
24
  @whitelist ||= if File.exist?(WHITELIST_FILE)
25
- YAML.load_file(File.expand_path(WHITELIST_FILE))
25
+ load_file(File.expand_path(WHITELIST_FILE))
26
26
  else
27
27
  []
28
28
  end
29
29
  end
30
+
31
+ def self.load_file(path)
32
+ Set.new(YAML.load_file(path))
33
+ end
30
34
  end
@@ -72,9 +72,12 @@ module ValidEmail2
72
72
 
73
73
  def domain_is_in?(domain_list)
74
74
  address_domain = address.domain.downcase
75
- domain_list.any? { |domain|
76
- address_domain.end_with?(domain) && address_domain =~ /\A(?:.+\.)*?#{domain}\z/
77
- }
75
+ return true if domain_list.include?(address_domain)
76
+
77
+ i = address_domain.index('.')
78
+ return false unless i
79
+
80
+ return domain_list.include?(address_domain[(i+1)..-1])
78
81
  end
79
82
 
80
83
  def mx_server_is_in?(domain_list)
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "3.0.5"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -31,6 +31,9 @@ class TestUserMessage < TestModel
31
31
  end
32
32
 
33
33
  describe ValidEmail2 do
34
+
35
+ let(:disposable_domain) { ValidEmail2.disposable_emails.first }
36
+
34
37
  describe "basic validation" do
35
38
  subject(:user) { TestUser.new(email: "") }
36
39
 
@@ -88,13 +91,18 @@ describe ValidEmail2 do
88
91
  expect(user.valid?).to be_truthy
89
92
  end
90
93
 
94
+ it "is valid if it just ends with a disposable domain" do
95
+ user = TestUserDisallowDisposable.new(email: "foo@nondisposable-0-mail.com")
96
+ expect(user.valid?).to be_truthy
97
+ end
98
+
91
99
  it "is invalid if it's a disposable email" do
92
- user = TestUserDisallowDisposable.new(email: "foo@#{ValidEmail2.disposable_emails.first}")
100
+ user = TestUserDisallowDisposable.new(email: "foo@#{disposable_domain}")
93
101
  expect(user.valid?).to be_falsey
94
102
  end
95
103
 
96
104
  it "is invalid if the domain is a subdomain of a disposable domain" do
97
- user = TestUserDisallowDisposable.new(email: "foo@bar.#{ValidEmail2.disposable_emails.first}")
105
+ user = TestUserDisallowDisposable.new(email: "foo@bar.#{disposable_domain}")
98
106
  expect(user.valid?).to be_falsey
99
107
  end
100
108
 
@@ -119,7 +127,7 @@ describe ValidEmail2 do
119
127
  end
120
128
 
121
129
  describe "with whitelisted emails" do
122
- let(:whitelist_domain) { ValidEmail2.disposable_emails.first }
130
+ let(:whitelist_domain) { disposable_domain }
123
131
  let(:whitelist_file_path) { "config/whitelisted_email_domains.yml" }
124
132
 
125
133
  after 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.0.5
4
+ version: 3.1.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: 2019-09-26 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler