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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81f002d3f49ad0c6c47542c4551e19d4f3c4eee5e7ac8a880843c72afca63580
4
- data.tar.gz: 83048195af9517187e998511ef33ba58813802110557305e5b0e195f5085833b
3
+ metadata.gz: 8cc608e090f5de38c7126888581eaad8610393e05e5d93a42494a6b35f44db4e
4
+ data.tar.gz: b95740599e8cad05d701563f613561e17a420fcc69e98afa7edcfcced19afdd8
5
5
  SHA512:
6
- metadata.gz: e1404b591d8639273063daeeaecdd8c53012d58c18e33286418f651372f8dd06513560ce2e0c2aac55db53ac081a8b11b9cb450520a66cf7b4506d86bce5f4b0
7
- data.tar.gz: 6c739f6f71eacb00db48cf0ed72ae6dbd564275e54943a5bb88f10d64878d96cf32600f60ff6ee4dd525e7e47968e0809306f9d88fc13aef1d2af5a91a2bc6cf
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 }
@@ -6,7 +6,7 @@ module ValidEmail2
6
6
  class Address
7
7
  attr_accessor :address
8
8
 
9
- PROHIBITED_DOMAIN_CHARACTERS_REGEX = /[+!_\s]/
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
- return false if @parse_error
27
-
28
- if address.domain && address.address == @raw_address
29
- domain = address.domain
30
-
31
- domain !~ PROHIBITED_DOMAIN_CHARACTERS_REGEX &&
32
- # Domain needs to have at least one dot
33
- domain =~ /\./ &&
34
- # Domain may not have two consecutive dots
35
- domain !~ /\.{2,}/ &&
36
- # Domain may not start with a dot
37
- domain !~ /^\./ &&
38
- # Domain may not start with a dash
39
- domain !~ /^-/ &&
40
- # Domain name may not end with a dash
41
- domain !~ /-\./ &&
42
- # Address may not contain a dot directly before @
43
- address.address !~ /\.@/
44
- else
45
- false
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
- valid? &&
55
- (
56
- domain_is_in?(ValidEmail2.disposable_emails) ||
57
- mx_server_is_in?(ValidEmail2.disposable_emails)
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
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "3.1.2"
2
+ VERSION = "3.1.3"
3
3
  end
@@ -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
- it "is invalid if it's a disposable email" do
115
- user = TestUserDisallowDisposable.new(email: "foo@#{disposable_domain}")
116
- expect(user.valid?).to be_falsey
117
- end
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
- it "is invalid if the domain is a subdomain of a disposable domain" do
120
- user = TestUserDisallowDisposable.new(email: "foo@bar.#{disposable_domain}")
121
- expect(user.valid?).to be_falsey
122
- end
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
- it "allows example.com" do
125
- user = TestUserDisallowDisposable.new(email: "foo@example.com")
126
- expect(user.valid?).to be_truthy
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.2
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-26 00:00:00.000000000 Z
11
+ date: 2019-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler