valid_email2 3.2.5 → 3.3.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: 826d65203316bb843deb2167608e1fcd087741ad0d2cbb96d123eb87997d633c
4
- data.tar.gz: 8e67f13e8b38393f0b8cf3d6562135bd1bdab809ce54c267c6fed615bbbd7304
3
+ metadata.gz: b11e62f82282c1cc81c9698a17a44af5d2a0baec3dc9a1f147e8b9f6201885cd
4
+ data.tar.gz: 24b9024326e7f3ad965802c320901f2ecbd42cfcfc7c0b06e757f73767a6ae92
5
5
  SHA512:
6
- metadata.gz: 8c2bef1c61e6cabfba92a339b4157809a090aafc709d18652f3c1e149bb438f8fcc79fddb467efba8fd859ac299926f9695c1d6f89b5b680bb1264e66029ffea
7
- data.tar.gz: 5626451520015990d7f1f64d6f34cabf75b38f9f3a82ca2c6af9616b0c03a50e43ef78ba733b59ec1818cd07b68eca10478a01a1085efa47295d6f31b1f41d30
6
+ metadata.gz: cbb94d6b281464231ef30464b775fcbe1d404a8651105b2fe4b488182bc3cdcce9b2140d0a24431db7570c302c85e353f16e4f4444cd4edda009645a64f54ed4
7
+ data.tar.gz: f5783382e56e570a02dd5abb0e7190d4f4e457a5b47e523bd21ddc4eab51fac7680811e2913e56e1db9ee1593f4c368c7f594558227ce635252c1a1e731a8484
@@ -1,3 +1,7 @@
1
+ ## Version 3.3.0
2
+ * Allow multiple addresses separated by comma (https://github.com/micke/valid_email2/pull/156)
3
+ * Make prohibited_domain_characters_regex changeable (https://github.com/micke/valid_email2/pull/157)
4
+
1
5
  ## Version 3.2.5
2
6
  * Remove false positives
3
7
  * Pull new domains
data/README.md CHANGED
@@ -83,6 +83,11 @@ To validate create your own custom message:
83
83
  validates :email, 'valid_email_2/email': { message: "is not a valid email" }
84
84
  ```
85
85
 
86
+ To allow multiple addresses separated by comma:
87
+ ```ruby
88
+ validates :email, 'valid_email_2/email': { multiple: true }
89
+ ```
90
+
86
91
  All together:
87
92
  ```ruby
88
93
  validates :email, 'valid_email_2/email': { mx: true, disposable: true, disallow_subaddressing: true}
@@ -10,6 +10,14 @@ module ValidEmail2
10
10
  DEFAULT_RECIPIENT_DELIMITER = '+'.freeze
11
11
  DOT_DELIMITER = '.'.freeze
12
12
 
13
+ def self.prohibited_domain_characters_regex
14
+ @prohibited_domain_characters_regex ||= PROHIBITED_DOMAIN_CHARACTERS_REGEX
15
+ end
16
+
17
+ def self.prohibited_domain_characters_regex=(val)
18
+ @prohibited_domain_characters_regex = val
19
+ end
20
+
13
21
  def initialize(address)
14
22
  @parse_error = false
15
23
  @raw_address = address
@@ -30,7 +38,7 @@ module ValidEmail2
30
38
  if address.domain && address.address == @raw_address
31
39
  domain = address.domain
32
40
 
33
- domain !~ PROHIBITED_DOMAIN_CHARACTERS_REGEX &&
41
+ domain !~ self.class.prohibited_domain_characters_regex &&
34
42
  # Domain needs to have at least one dot
35
43
  domain =~ /\./ &&
36
44
  # Domain may not have two consecutive dots
@@ -5,43 +5,44 @@ require "active_model/validations"
5
5
  module ValidEmail2
6
6
  class EmailValidator < ActiveModel::EachValidator
7
7
  def default_options
8
- { regex: true, disposable: false, mx: false, disallow_subaddressing: false }
8
+ { regex: true, disposable: false, mx: false, disallow_subaddressing: false, multiple: false }
9
9
  end
10
10
 
11
11
  def validate_each(record, attribute, value)
12
12
  return unless value.present?
13
13
  options = default_options.merge(self.options)
14
14
 
15
- address = ValidEmail2::Address.new(value)
15
+ value_spitted = options[:multiple] ? value.split(',').map(&:strip) : [value]
16
+ addresses = value_spitted.map { |v| ValidEmail2::Address.new(v) }
16
17
 
17
- error(record, attribute) && return unless address.valid?
18
+ error(record, attribute) && return unless addresses.all?(&:valid?)
18
19
 
19
20
  if options[:disallow_dotted]
20
- error(record, attribute) && return if address.dotted?
21
+ error(record, attribute) && return if addresses.any?(&:dotted?)
21
22
  end
22
23
 
23
24
  if options[:disallow_subaddressing]
24
- error(record, attribute) && return if address.subaddressed?
25
+ error(record, attribute) && return if addresses.any?(&:subaddressed?)
25
26
  end
26
27
 
27
28
  if options[:disposable]
28
- error(record, attribute) && return if address.disposable?
29
+ error(record, attribute) && return if addresses.any?(&:disposable?)
29
30
  end
30
31
 
31
32
  if options[:disposable_domain]
32
- error(record, attribute) && return if address.disposable_domain?
33
+ error(record, attribute) && return if addresses.any?(&:disposable_domain?)
33
34
  end
34
35
 
35
36
  if options[:disposable_with_whitelist]
36
- error(record, attribute) && return if address.disposable? && !address.whitelisted?
37
+ error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.whitelisted? }
37
38
  end
38
39
 
39
40
  if options[:blacklist]
40
- error(record, attribute) && return if address.blacklisted?
41
+ error(record, attribute) && return if addresses.any?(&:blacklisted?)
41
42
  end
42
43
 
43
44
  if options[:mx]
44
- error(record, attribute) && return unless address.valid_mx?
45
+ error(record, attribute) && return unless addresses.all?(&:valid_mx?)
45
46
  end
46
47
  end
47
48
 
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "3.2.5"
2
+ VERSION = "3.3.0"
3
3
  end
@@ -39,6 +39,10 @@ class TestUserMessage < TestModel
39
39
  validates :email, 'valid_email_2/email': { message: "custom message" }
40
40
  end
41
41
 
42
+ class TestUserMultiple < TestModel
43
+ validates :email, 'valid_email_2/email': { multiple: true }
44
+ end
45
+
42
46
  describe ValidEmail2 do
43
47
 
44
48
  let(:disposable_domain) { ValidEmail2.disposable_emails.first }
@@ -244,6 +248,20 @@ describe ValidEmail2 do
244
248
  end
245
249
  end
246
250
 
251
+ describe "with multiple addresses" do
252
+ it "tests each address for it's own" do
253
+ user = TestUserMultiple.new(email: "foo@gmail.com, bar@gmail.com")
254
+ expect(user.valid?).to be_truthy
255
+ end
256
+
257
+ context 'when one address is invalid' do
258
+ it "fails for all" do
259
+ user = TestUserMultiple.new(email: "foo@gmail.com, bar@123")
260
+ expect(user.valid?).to be_falsey
261
+ end
262
+ end
263
+ end
264
+
247
265
  describe "#dotted?" do
248
266
  it "is true when address local part contains a dot delimiter ('.')" do
249
267
  email = ValidEmail2::Address.new("john.doe@gmail.com")
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.2.5
4
+ version: 3.3.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-08-06 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler