valid_email2 3.3.0 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/valid_email2.rb +28 -16
- data/lib/valid_email2/address.rb +10 -15
- data/lib/valid_email2/version.rb +1 -1
- data/spec/benchmark_spec.rb +18 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/valid_email2_spec.rb +1 -6
- data/valid_email2.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe834d489ba46cf4a8262cb077bf2f88b0fd866b604bf1ae628d877bbfdbb57b
|
4
|
+
data.tar.gz: af8e27efffae003ed85189ae10d1f9b6e30817e8529deb4064811156a332208e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 300c5f449125f0d6bd1abfd224aa88c65caa0377fe2b2a56ec6bc695bb3c0e9bac4ea03f2c091509c19f5cb8614137578ec8fc52a844cfd0765f9da7d5707615
|
7
|
+
data.tar.gz: ce9dfe893b11555a195f4777e3146f0065c3d49c26b289e874d01cb40da0f02f575f5a3efd8430e57bffdd2aaf52a36f05056986b789b3bd982b14d889bea0e2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## Version 3.3.1
|
2
|
+
* Fix some performance regressions (https://github.com/micke/valid_email2/pull/150)
|
3
|
+
|
1
4
|
## Version 3.3.0
|
2
5
|
* Allow multiple addresses separated by comma (https://github.com/micke/valid_email2/pull/156)
|
3
6
|
* Make prohibited_domain_characters_regex changeable (https://github.com/micke/valid_email2/pull/157)
|
data/lib/valid_email2.rb
CHANGED
@@ -7,23 +7,35 @@ module ValidEmail2
|
|
7
7
|
WHITELIST_FILE = "config/whitelisted_email_domains.yml"
|
8
8
|
DISPOSABLE_FILE = File.expand_path('../config/disposable_email_domains.txt', __dir__)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
class << self
|
11
|
+
def disposable_emails
|
12
|
+
@disposable_emails ||= load_file(DISPOSABLE_FILE)
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def blacklist
|
16
|
+
@blacklist ||= load_if_exists(BLACKLIST_FILE)
|
17
|
+
end
|
18
|
+
|
19
|
+
def whitelist
|
20
|
+
@whitelist ||= load_if_exists(WHITELIST_FILE)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def load_if_exists(path)
|
26
|
+
File.exist?(path) ? load_file(path) : Set.new
|
27
|
+
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
def load_file(path)
|
30
|
+
# This method MUST return a Set, otherwise the
|
31
|
+
# performance will suffer!
|
32
|
+
if path.end_with?(".yml")
|
33
|
+
Set.new(YAML.load_file(path))
|
34
|
+
else
|
35
|
+
File.open(path, "r").each_line.each_with_object(Set.new) do |domain, set|
|
36
|
+
set << domain.tap(&:chomp!)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
28
40
|
end
|
29
41
|
end
|
data/lib/valid_email2/address.rb
CHANGED
@@ -32,25 +32,20 @@ module ValidEmail2
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def valid?
|
35
|
-
@valid
|
36
|
-
|
35
|
+
return @valid unless @valid.nil?
|
36
|
+
return false if @parse_error
|
37
37
|
|
38
|
+
@valid = begin
|
38
39
|
if address.domain && address.address == @raw_address
|
39
40
|
domain = address.domain
|
40
41
|
|
41
42
|
domain !~ self.class.prohibited_domain_characters_regex &&
|
42
|
-
|
43
|
-
domain
|
44
|
-
|
45
|
-
domain
|
46
|
-
|
47
|
-
|
48
|
-
# Domain may not start with a dash
|
49
|
-
domain !~ /^-/ &&
|
50
|
-
# Domain name may not end with a dash
|
51
|
-
domain !~ /-\./ &&
|
52
|
-
# Address may not contain a dot directly before @
|
53
|
-
address.address !~ /\.@/
|
43
|
+
domain.include?('.') &&
|
44
|
+
!domain.include?('..') &&
|
45
|
+
!domain.start_with?('.') &&
|
46
|
+
!domain.start_with?('-') &&
|
47
|
+
!domain.include?('-.') &&
|
48
|
+
!address.local.end_with?('.')
|
54
49
|
else
|
55
50
|
false
|
56
51
|
end
|
@@ -70,7 +65,7 @@ module ValidEmail2
|
|
70
65
|
end
|
71
66
|
|
72
67
|
def disposable_domain?
|
73
|
-
|
68
|
+
domain_is_in?(ValidEmail2.disposable_emails)
|
74
69
|
end
|
75
70
|
|
76
71
|
def disposable_mx_server?
|
data/lib/valid_email2/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Performance testing" do
|
6
|
+
let(:disposable_domain) { ValidEmail2.disposable_emails.first }
|
7
|
+
|
8
|
+
it "has acceptable lookup performance" do
|
9
|
+
address = ValidEmail2::Address.new("test@example.com")
|
10
|
+
|
11
|
+
# preload list and check size
|
12
|
+
expect(ValidEmail2.disposable_emails).to be_a(Set)
|
13
|
+
expect(ValidEmail2.disposable_emails.count).to be > 30000
|
14
|
+
|
15
|
+
# check lookup timing
|
16
|
+
expect { address.disposable_domain? }.to perform_under(0.0001).sample(10).times
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
$:.unshift File.expand_path("../lib",__FILE__)
|
2
2
|
require "valid_email2"
|
3
3
|
|
4
|
+
# Include and configure benchmark
|
5
|
+
require 'rspec-benchmark'
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.include RSpec::Benchmark::Matchers
|
8
|
+
end
|
9
|
+
RSpec::Benchmark.configure do |config|
|
10
|
+
config.disable_gc = true
|
11
|
+
end
|
12
|
+
|
4
13
|
class TestModel
|
5
14
|
include ActiveModel::Validations
|
6
15
|
|
data/spec/valid_email2_spec.rb
CHANGED
@@ -87,16 +87,11 @@ describe ValidEmail2 do
|
|
87
87
|
expect(user.valid?).to be_falsey
|
88
88
|
end
|
89
89
|
|
90
|
-
it "is invalid if the
|
90
|
+
it "is invalid if the email contains emoticons" do
|
91
91
|
user = TestUser.new(email: "foo🙈@gmail.com")
|
92
92
|
expect(user.valid?).to be_falsy
|
93
93
|
end
|
94
94
|
|
95
|
-
it "is invalid if the domain contains .@ consecutively" do
|
96
|
-
user = TestUser.new(email: "foo.@gmail.com")
|
97
|
-
expect(user.valid?).to be_falsy
|
98
|
-
end
|
99
|
-
|
100
95
|
it "is invalid if the domain contains spaces" do
|
101
96
|
user = TestUser.new(email: "user@gmail .com")
|
102
97
|
expect(user.valid?).to be_falsy
|
data/valid_email2.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 2.0"
|
24
24
|
spec.add_development_dependency "rake", "~> 12.3.3"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.5.0"
|
26
|
+
spec.add_development_dependency "rspec-benchmark", "~> 0.6"
|
26
27
|
spec.add_development_dependency "pry"
|
27
28
|
spec.add_runtime_dependency "mail", "~> 2.5"
|
28
29
|
spec.add_runtime_dependency "activemodel", ">= 3.2"
|
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.3.
|
4
|
+
version: 3.3.1
|
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-08-
|
11
|
+
date: 2020-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-benchmark
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +134,7 @@ files:
|
|
120
134
|
- lib/valid_email2/email_validator.rb
|
121
135
|
- lib/valid_email2/version.rb
|
122
136
|
- pull_mailchecker_emails.rb
|
137
|
+
- spec/benchmark_spec.rb
|
123
138
|
- spec/spec_helper.rb
|
124
139
|
- spec/valid_email2_spec.rb
|
125
140
|
- valid_email2.gemspec
|
@@ -148,5 +163,6 @@ specification_version: 4
|
|
148
163
|
summary: ActiveModel validation for email. Including MX lookup and disposable email
|
149
164
|
blacklist
|
150
165
|
test_files:
|
166
|
+
- spec/benchmark_spec.rb
|
151
167
|
- spec/spec_helper.rb
|
152
168
|
- spec/valid_email2_spec.rb
|