valid_email2 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4846126777b929a2c98071c1a37d123f862f27cb
4
- data.tar.gz: 34855d8b778cdf6a2b37d367ad3c0bad450d13e9
3
+ metadata.gz: 92a77a86b9cfbe45f43ed7e3b09a2a93ed8a86c6
4
+ data.tar.gz: 81e19c05fb443aad512cf4baa2e9db27d26aed79
5
5
  SHA512:
6
- metadata.gz: 85bfaea5ddd6e2d71d271f5c4cc6c5fda4b13c1e297d19357e496a6daaccf39d6b95dcf73e7b91177b26cf414ebb7a16a9e141a09fa270fd9d80c50f8d427e58
7
- data.tar.gz: 8cbf2ca1cc79031ccdf1c5fa37131993dc2dab391191df74356a65ce8a3c07e13c398a7e0d52ff6bba55abc72688c775cdf0561c33dcffaea99e182af0b1d942
6
+ metadata.gz: d716cf815c183d18534823e6aece0053a05d4a1dd1d9b7a308891a7bc46be0f28f75a9e9b957fe1bbb94474b27f11660c83e777605e96a5966de37925908d6c3
7
+ data.tar.gz: 458d3b946e5d84a4ab83c677698a9d1a81cad2a169a36d93e4ed1daf859894a1b0802f97478326d8f6071234fcd378aabc9169467e6b940763016d88c82253f0
@@ -1,3 +1,6 @@
1
+ ## Version 2.2.2
2
+ Remove false-positive 163.com (https://github.com/lisinge/valid_email2/issues/105)
3
+
1
4
  ## Version 2.2.1
2
5
  Fix regression where `ValidEmail2::Address.new` couldn't handle the address
3
6
  being nil (https://github.com/lisinge/valid_email2/issues/102)
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Validate emails with the help of the `mail` gem instead of some clunky regexp.
6
6
  Aditionally validate that the domain has a MX record.
7
7
  Optionally validate against a static [list of disposable email services](vendor/disposable_emails.yml).
8
-
8
+ Optionally validate that the email is not subaddressed ([RFC5233](https://tools.ietf.org/html/rfc5233)).
9
9
 
10
10
  ### Why?
11
11
 
@@ -58,9 +58,14 @@ To validate that the domain is not blacklisted (under vendor/blacklist.yml):
58
58
  validates :email, 'valid_email_2/email': { blacklist: true }
59
59
  ```
60
60
 
61
+ To validate that email is not subaddressed:
62
+ ```ruby
63
+ validates :email, 'valid_email_2/email': { disallow_subaddressing: true }
64
+ ```
65
+
61
66
  All together:
62
67
  ```ruby
63
- validates :email, 'valid_email_2/email': { mx: true, disposable: true }
68
+ validates :email, 'valid_email_2/email': { mx: true, disposable: true, disallow_subaddressing: true}
64
69
  ```
65
70
 
66
71
  > Note that this gem will let an empty email pass through so you will need to
@@ -73,6 +78,7 @@ address = ValidEmail2::Address.new("lisinge@gmail.com")
73
78
  address.valid? => true
74
79
  address.disposable? => false
75
80
  address.valid_mx? => true
81
+ address.subaddressed? => false
76
82
  ```
77
83
 
78
84
  ### Test environment
@@ -7,6 +7,7 @@ module ValidEmail2
7
7
  attr_accessor :address
8
8
 
9
9
  ALLOWED_DOMAIN_CHARACTERS_REGEX = /\A[a-z0-9\-.]+\z/i
10
+ DEFAULT_RECIPIENT_DELIMITER = '+'.freeze
10
11
 
11
12
  def initialize(address)
12
13
  @parse_error = false
@@ -39,6 +40,10 @@ module ValidEmail2
39
40
  end
40
41
  end
41
42
 
43
+ def subaddressed?
44
+ valid? && address.local.include?(DEFAULT_RECIPIENT_DELIMITER)
45
+ end
46
+
42
47
  def disposable?
43
48
  valid? && domain_is_in?(ValidEmail2.disposable_emails)
44
49
  end
@@ -5,7 +5,7 @@ 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 }
8
+ { regex: true, disposable: false, mx: false, disallow_subaddressing: false }
9
9
  end
10
10
 
11
11
  def validate_each(record, attribute, value)
@@ -16,6 +16,10 @@ module ValidEmail2
16
16
 
17
17
  error(record, attribute) && return unless address.valid?
18
18
 
19
+ if options[:disallow_subaddressing]
20
+ error(record, attribute) && return if address.subaddressed?
21
+ end
22
+
19
23
  if options[:disposable]
20
24
  error(record, attribute) && return if address.disposable?
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -4,6 +4,10 @@ class TestUser < TestModel
4
4
  validates :email, 'valid_email_2/email': true
5
5
  end
6
6
 
7
+ class TestUserSubaddressing < TestModel
8
+ validates :email, 'valid_email_2/email': {disallow_subaddressing: true}
9
+ end
10
+
7
11
  class TestUserMX < TestModel
8
12
  validates :email, 'valid_email_2/email': { mx: true }
9
13
  end
@@ -115,4 +119,52 @@ describe ValidEmail2 do
115
119
  expect(email.valid?).to be_falsy
116
120
  end
117
121
  end
122
+
123
+ describe "subaddressed emails" do
124
+
125
+ describe "::Address::DEFAULT_RECIPIENT_DELIMITER" do
126
+ it "should be recipient delimiter ('+')" do
127
+ expect(ValidEmail2::Address::DEFAULT_RECIPIENT_DELIMITER).to eq('+')
128
+ end
129
+ end
130
+
131
+ describe "::Address#subaddressed?" do
132
+ it "should be true when address local part contains a recipient delimiter ('+')" do
133
+ email = ValidEmail2::Address.new("foo+1@gmail.com")
134
+ expect(email.subaddressed?).to be_truthy
135
+ end
136
+
137
+ it "should be false when address local part contains a recipient delimiter ('+')" do
138
+ email = ValidEmail2::Address.new("foo@gmail.com")
139
+ expect(email.subaddressed?).to be_falsey
140
+ end
141
+ end
142
+
143
+ describe "user validation" do
144
+ context "subaddressing is allowed (default)" do
145
+ it "should be valid when address local part does not contain a recipient delimiter ('+')" do
146
+ user = TestUser.new(email: "foo@gmail.com")
147
+ expect(user.valid?).to be_truthy
148
+ end
149
+
150
+ it "should be valid when address local part contains a recipient delimiter ('+')" do
151
+ user = TestUser.new(email: "foo+1@gmail.com")
152
+ expect(user.valid?).to be_truthy
153
+ end
154
+ end
155
+
156
+ context "subaddressing is forbidden" do
157
+ it "should be valid when address local part does not contain a recipient delimiter ('+')" do
158
+ user = TestUserSubaddressing.new(email: "foo@gmail.com")
159
+ expect(user.valid?).to be_truthy
160
+ end
161
+
162
+ it "should be invalid when address local part contains a recipient delimiter ('+')" do
163
+ user = TestUserSubaddressing.new(email: "foo+1@gmail.com")
164
+ expect(user.valid?).to be_falsey
165
+ end
166
+ end
167
+ end
168
+
169
+ end
118
170
  end
@@ -68,7 +68,6 @@
68
68
  - 14n.co.uk
69
69
  - 15qm-mail.red
70
70
  - 15qm.com
71
- - 163.com
72
71
  - 188.com
73
72
  - 189.cn
74
73
  - 1ce.us
@@ -883,6 +882,7 @@
883
882
  - ckaazaza.tk
884
883
  - ckiso.com
885
884
  - cko.kr
885
+ - ckoie.com
886
886
  - cl-cl.org
887
887
  - cl.gl
888
888
  - cl0ne.net
@@ -2597,6 +2597,7 @@
2597
2597
  - loadby.us
2598
2598
  - loan101.pro
2599
2599
  - loaoa.com
2600
+ - loapq.com
2600
2601
  - localserv.no-ip.org
2601
2602
  - locanto1.club
2602
2603
  - locantofuck.top
@@ -4046,6 +4047,7 @@
4046
4047
  - sogetthis.com
4047
4048
  - sohai.ml
4048
4049
  - sohu.com
4050
+ - soioa.com
4049
4051
  - soisz.com
4050
4052
  - solar-impact.pro
4051
4053
  - solvemail.info
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: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micke Lisinge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-27 00:00:00.000000000 Z
11
+ date: 2018-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler