valid_email2 5.2.6 → 5.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: b0a01a2acf82274bd6e459721211ff637ab27f24ca2ec01ae4423ed4ffac25d9
4
- data.tar.gz: cd8506ab6c60327a789e2fb4f1d702a49a2059ff2c9af79c6db10ecb0c7023b0
3
+ metadata.gz: 0e044955522eceb44fb1def3eb4da317dc58625072d0c41f509ce50cc5634d4b
4
+ data.tar.gz: bc1af776d07f7a8480441d4bbf3f711d48cc7292947b8e004e1831be71e603bc
5
5
  SHA512:
6
- metadata.gz: 91af74f0a0c8fecac0ade9e9320186c0e86c76e48665d07ab79fe9ef0fdde75a3ff37d0d39b2cce8e2fd30a04a4815492ab5f24e7094f55b7852e3a6b41aef95
7
- data.tar.gz: d19d1e8c83b8aa2833ed2d472e41b8722018d08d5d465416f4cefc8c588dd9a9334d07401787acb9cee89cc9b326892097a6d3ad5d5ff015b0bce774bdbfc4ee
6
+ metadata.gz: 1974e08b667ae079117faf1415047fccebcb4a870bd1006a240ee15990bcee39ef75999a55ecc33e812c053a0c218afb0a80df7cf8b8379f3e9343583f7de51f
7
+ data.tar.gz: '085e865491902d39d25a49cf0834743cfc0280dee0a1b6f9358e265e8a473a0381b9da929edf8848b782e4e95715f8d58af66836f65e600bb511d06b651b2675'
@@ -1,5 +1,5 @@
1
1
  name: CI
2
- on: [push, pull_request]
2
+ on: [push, pull_request_target]
3
3
  jobs:
4
4
  test:
5
5
  strategy:
@@ -1 +1 @@
1
- {".":"5.2.6"}
1
+ {".":"5.3.0"}
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.3.0](https://github.com/micke/valid_email2/compare/v5.2.6...v5.3.0) (2024-08-31)
4
+
5
+
6
+ ### Features
7
+
8
+ * Deprecate blacklist and whitelist naming ([9df0bf8](https://github.com/micke/valid_email2/commit/9df0bf8c9912721b007e5a6acc67f533ca560c9f))
9
+ * Warn when loading deprecated files ([46634df](https://github.com/micke/valid_email2/commit/46634dff409f9a47f10684d629dc022b22daf362))
10
+
3
11
  ## [5.2.6](https://github.com/micke/valid_email2/compare/v5.2.5...v5.2.6) (2024-08-10)
4
12
 
5
13
 
data/README.md CHANGED
@@ -73,20 +73,20 @@ To validate that the domain is not a disposable email (checks domain only, does
73
73
  validates :email, 'valid_email_2/email': { disposable_domain: true }
74
74
  ```
75
75
 
76
- To validate that the domain is not a disposable email or a disposable email (checks domain and MX server) but whitelisted (under config/whitelisted_email_domains.yml):
76
+ To validate that the domain is not a disposable email or a disposable email (checks domain and MX server) but allow-listed (under config/allow_listed_email_domains.yml):
77
77
  ```ruby
78
- validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
78
+ validates :email, 'valid_email_2/email': { disposable_with_allow_list: true }
79
79
  ```
80
80
 
81
- To validate that the domain is not a disposable email or a disposable email (checks domain only, does not check MX server) but whitelisted (under config/whitelisted_email_domains.yml):
81
+ To validate that the domain is not a disposable email or a disposable email (checks domain only, does not check MX server) but allow-listed (under config/allow_listed_email_domains.yml):
82
82
 
83
83
  ```ruby
84
- validates :email, 'valid_email_2/email': { disposable_domain_with_whitelist: true }
84
+ validates :email, 'valid_email_2/email': { disposable_domain_with_allow_list: true }
85
85
  ```
86
86
 
87
- To validate that the domain is not blacklisted (under config/blacklisted_email_domains.yml):
87
+ To validate that the domain is not on the deny list (under config/deny_list_email_domains.yml):
88
88
  ```ruby
89
- validates :email, 'valid_email_2/email': { blacklist: true }
89
+ validates :email, 'valid_email_2/email': { deny_list: true }
90
90
  ```
91
91
 
92
92
  To validate that email is not subaddressed:
@@ -147,6 +147,15 @@ end
147
147
 
148
148
  This gem is tested against currently supported Ruby and Rails versions. For an up to date list, check the build matrix in the [workflow](.github/workflows/ci.yaml).
149
149
 
150
+ ## Upgrading to v5.3.0
151
+
152
+ In version v5.3.0 the config directory files were renamed as follows:
153
+
154
+ `config/blacklisted_email_domains.yml` -> `config/deny_listed_email_domains.yml`
155
+ `config/whitelisted_email_domains.yml` -> `config/allow_listed_email_domains.yml`
156
+
157
+ You won't need to make any changes yourself if you're installing this version for the first time. For individuals updating from earlier versions, make sure to update the file namings as per the above. In future versions this will be a breaking change.
158
+
150
159
  ## Upgrading to v3.0.0
151
160
 
152
161
  In version v3.0.0 I decided to move __and__ rename the config files from the
@@ -0,0 +1 @@
1
+ - deny-listed-test.com
@@ -0,0 +1,14 @@
1
+ module DeprecationHelper
2
+ def deprecate_method(old_method, new_method)
3
+ define_method(old_method) do |*args, &block|
4
+ klass = is_a? Module
5
+ target = klass ? "#{self}." : "#{self.class}#"
6
+ warn "Warning: `#{target}#{old_method}` is deprecated and will be removed in version 6 of valid_email2; use `#{new_method}` instead."
7
+ send(new_method, *args, &block)
8
+ end
9
+ end
10
+
11
+ def deprecation_message(old_name, new_name)
12
+ warn "Warning: `#{old_name}` is deprecated and will be removed in version 6 of valid_email2; use `#{new_name}` instead."
13
+ end
14
+ end
@@ -3,9 +3,12 @@
3
3
  require "valid_email2"
4
4
  require "resolv"
5
5
  require "mail"
6
+ require_relative "../helpers/deprecation_helper"
6
7
 
7
8
  module ValidEmail2
8
9
  class Address
10
+ extend DeprecationHelper
11
+
9
12
  attr_accessor :address
10
13
 
11
14
  PROHIBITED_DOMAIN_CHARACTERS_REGEX = /[+!_\/\s'`]/
@@ -84,13 +87,15 @@ module ValidEmail2
84
87
  valid? && mx_server_is_in?(ValidEmail2.disposable_emails)
85
88
  end
86
89
 
87
- def whitelisted?
88
- domain_is_in?(ValidEmail2.whitelist)
90
+ def allow_listed?
91
+ domain_is_in?(ValidEmail2.allow_list)
89
92
  end
93
+ deprecate_method :whitelisted?, :allow_listed?
90
94
 
91
- def blacklisted?
92
- valid? && domain_is_in?(ValidEmail2.blacklist)
95
+ def deny_listed?
96
+ valid? && domain_is_in?(ValidEmail2.deny_list)
93
97
  end
98
+ deprecate_method :blacklisted?, :deny_listed?
94
99
 
95
100
  def valid_mx?
96
101
  return false unless valid?
@@ -1,9 +1,12 @@
1
1
  require "valid_email2/address"
2
2
  require "active_model"
3
3
  require "active_model/validations"
4
+ require_relative "../helpers/deprecation_helper"
4
5
 
5
6
  module ValidEmail2
6
7
  class EmailValidator < ActiveModel::EachValidator
8
+ include DeprecationHelper
9
+
7
10
  def default_options
8
11
  { disposable: false, mx: false, strict_mx: false, disallow_subaddressing: false, multiple: false, dns_timeout: 5, dns_nameserver: nil }
9
12
  end
@@ -33,15 +36,27 @@ module ValidEmail2
33
36
  end
34
37
 
35
38
  if options[:disposable_with_whitelist]
36
- error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.whitelisted? }
39
+ deprecation_message(:disposable_with_whitelist, :disposable_with_allow_list)
40
+ end
41
+
42
+ if options[:disposable_with_allow_list] || options[:disposable_with_whitelist]
43
+ error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.allow_listed? }
37
44
  end
38
45
 
39
46
  if options[:disposable_domain_with_whitelist]
40
- error(record, attribute) && return if addresses.any? { |address| address.disposable_domain? && !address.whitelisted? }
47
+ deprecation_message(:disposable_domain_with_whitelist, :disposable_domain_with_allow_list)
48
+ end
49
+
50
+ if options[:disposable_domain_with_allow_list] || options[:disposable_domain_with_whitelist]
51
+ error(record, attribute) && return if addresses.any? { |address| address.disposable_domain? && !address.allow_listed? }
41
52
  end
42
53
 
43
54
  if options[:blacklist]
44
- error(record, attribute) && return if addresses.any?(&:blacklisted?)
55
+ deprecation_message(:blacklist, :deny_list)
56
+ end
57
+
58
+ if options[:deny_list] || options[:blacklist]
59
+ error(record, attribute) && return if addresses.any?(&:deny_listed?)
45
60
  end
46
61
 
47
62
  if options[:mx]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal:true
2
2
 
3
3
  module ValidEmail2
4
- VERSION = "5.2.6"
4
+ VERSION = "5.3.0"
5
5
  end
data/lib/valid_email2.rb CHANGED
@@ -1,29 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "valid_email2/email_validator"
4
+ require_relative "./helpers/deprecation_helper"
4
5
 
5
6
  module ValidEmail2
7
+
6
8
  BLACKLIST_FILE = "config/blacklisted_email_domains.yml"
9
+ DENY_LIST_FILE = "config/deny_listed_email_domains.yml"
7
10
  WHITELIST_FILE = "config/whitelisted_email_domains.yml"
11
+ ALLOW_LIST_FILE = "config/allow_listed_email_domains.yml"
8
12
  DISPOSABLE_FILE = File.expand_path('../config/disposable_email_domains.txt', __dir__)
9
13
 
10
14
  class << self
15
+ extend DeprecationHelper
16
+
11
17
  def disposable_emails
12
18
  @disposable_emails ||= load_file(DISPOSABLE_FILE)
13
19
  end
14
20
 
15
- def blacklist
16
- @blacklist ||= load_if_exists(BLACKLIST_FILE)
21
+ def deny_list
22
+ @deny_list ||= load_if_exists(DENY_LIST_FILE) ||
23
+ load_deprecated_if_exists(BLACKLIST_FILE) ||
24
+ Set.new
17
25
  end
26
+ deprecate_method :blacklist, :deny_list
18
27
 
19
- def whitelist
20
- @whitelist ||= load_if_exists(WHITELIST_FILE)
28
+ def allow_list
29
+ @allow_list ||= load_if_exists(ALLOW_LIST_FILE) ||
30
+ load_deprecated_if_exists(WHITELIST_FILE) ||
31
+ Set.new
21
32
  end
33
+ deprecate_method :whitelist, :allow_list
22
34
 
23
35
  private
24
36
 
25
37
  def load_if_exists(path)
26
- File.exist?(path) ? load_file(path) : Set.new
38
+ load_file(path) if File.exist?(path)
39
+ end
40
+
41
+ def load_deprecated_if_exists(path)
42
+ if File.exist?(path)
43
+ warn <<~WARN
44
+ Warning: The file `#{path}` used by valid_email2 is deprecated and won't be read in version 6 of valid_email2;
45
+ Rename the file to `#{path.gsub("blacklisted", "deny_listed").gsub("whitelisted", "allow_listed")}` instead."
46
+ WARN
47
+ load_file(path)
48
+ end
27
49
  end
28
50
 
29
51
  def load_file(path)
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "release-type": "ruby",
3
3
  "include-component-in-tag": false,
4
- "last-release-sha": "b327e76f71e764f6d76351425e11d1563e04f188",
5
4
  "packages": {
6
5
  ".": {
7
6
  "release-type": "ruby",
@@ -47,16 +47,16 @@ class TestUserDisallowDisposableDomain < TestModel
47
47
  validates :email, 'valid_email_2/email': { disposable_domain: true }
48
48
  end
49
49
 
50
- class TestUserDisallowDisposableWithWhitelist < TestModel
51
- validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
50
+ class TestUserDisallowDisposableWithAllowList < TestModel
51
+ validates :email, 'valid_email_2/email': { disposable_with_allow_list: true }
52
52
  end
53
53
 
54
- class TestUserDisallowDisposableDomainWithWhitelist < TestModel
55
- validates :email, 'valid_email_2/email': { disposable_domain_with_whitelist: true }
54
+ class TestUserDisallowDisposableDomainWithAllowList < TestModel
55
+ validates :email, 'valid_email_2/email': { disposable_domain_with_allow_list: true }
56
56
  end
57
57
 
58
- class TestUserDisallowBlacklisted < TestModel
59
- validates :email, 'valid_email_2/email': { blacklist: true }
58
+ class TestUserDisallowDenyListed < TestModel
59
+ validates :email, 'valid_email_2/email': { deny_list: true }
60
60
  end
61
61
 
62
62
  class TestUserMessage < TestModel
@@ -208,58 +208,58 @@ describe ValidEmail2 do
208
208
  end
209
209
  end
210
210
 
211
- describe "with whitelisted emails" do
212
- let(:whitelist_domain) { disposable_domain }
213
- let(:whitelist_file_path) { "config/whitelisted_email_domains.yml" }
211
+ describe "with allow-listed emails" do
212
+ let(:allow_list_domain) { disposable_domain }
213
+ let(:allow_list_file_path) { "config/allow_listed_email_domains.yml" }
214
214
 
215
- # Some of the specs below need to explictly set the whitelist var or it
215
+ # Some of the specs below need to explictly set the allow list var or it
216
216
  # may be cached to an empty set
217
- def set_whitelist
217
+ def set_allow_list
218
218
  ValidEmail2.instance_variable_set(
219
- :@whitelist,
220
- ValidEmail2.send(:load_if_exists, ValidEmail2::WHITELIST_FILE)
219
+ :@allow_list,
220
+ ValidEmail2.send(:load_if_exists, ValidEmail2::ALLOW_LIST_FILE)
221
221
  )
222
222
  end
223
223
 
224
224
  after do
225
- FileUtils.rm(whitelist_file_path, force: true)
226
- set_whitelist
225
+ FileUtils.rm(allow_list_file_path, force: true)
226
+ set_allow_list
227
227
  end
228
228
 
229
- it "is invalid if the domain is disposable and not in the whitelist" do
230
- user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{whitelist_domain}")
229
+ it "is invalid if the domain is disposable and not in the allow list" do
230
+ user = TestUserDisallowDisposableWithAllowList.new(email: "foo@#{allow_list_domain}")
231
231
  expect(user.valid?).to be_falsey
232
232
  end
233
233
 
234
- it "is valid if the domain is disposable but in the whitelist" do
235
- File.open(whitelist_file_path, "w") { |f| f.write [whitelist_domain].to_yaml }
236
- set_whitelist
237
- user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{whitelist_domain}")
234
+ it "is valid if the domain is disposable but in the allow list" do
235
+ File.open(allow_list_file_path, "w") { |f| f.write [allow_list_domain].to_yaml }
236
+ set_allow_list
237
+ user = TestUserDisallowDisposableWithAllowList.new(email: "foo@#{allow_list_domain}")
238
238
  expect(user.valid?).to be_truthy
239
239
  end
240
240
 
241
- it "is invalid if the domain is a disposable_domain and not in the whitelist" do
242
- user = TestUserDisallowDisposableDomainWithWhitelist.new(email: "foo@#{whitelist_domain}")
241
+ it "is invalid if the domain is a disposable_domain and not in the allow list" do
242
+ user = TestUserDisallowDisposableDomainWithAllowList.new(email: "foo@#{allow_list_domain}")
243
243
  expect(user.valid?).to be_falsey
244
244
  end
245
245
 
246
- it "is valid if the domain is a disposable_domain but in the whitelist" do
247
- File.open(whitelist_file_path, "w") { |f| f.write [whitelist_domain].to_yaml }
248
- set_whitelist
249
- user = TestUserDisallowDisposableDomainWithWhitelist.new(email: "foo@#{whitelist_domain}")
246
+ it "is valid if the domain is a disposable_domain but in the allow list" do
247
+ File.open(allow_list_file_path, "w") { |f| f.write [allow_list_domain].to_yaml }
248
+ set_allow_list
249
+ user = TestUserDisallowDisposableDomainWithAllowList.new(email: "foo@#{allow_list_domain}")
250
250
  expect(user.valid?).to be_truthy
251
251
  end
252
252
  end
253
253
  end
254
254
 
255
- describe "with blacklist validation" do
256
- it "is valid if the domain is not blacklisted" do
257
- user = TestUserDisallowBlacklisted.new(email: "foo@gmail.com")
255
+ describe "with deny list validation" do
256
+ it "is valid if the domain is not deny-listed" do
257
+ user = TestUserDisallowDenyListed.new(email: "foo@gmail.com")
258
258
  expect(user.valid?).to be_truthy
259
259
  end
260
260
 
261
- it "is invalid if the domain is blacklisted" do
262
- user = TestUserDisallowBlacklisted.new(email: "foo@blacklisted-test.com")
261
+ it "is invalid if the domain is deny-listed" do
262
+ user = TestUserDisallowDenyListed.new(email: "foo@deny-listed-test.com")
263
263
  expect(user.valid?).to be_falsey
264
264
  end
265
265
  end
data/valid_email2.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ValidEmail2::VERSION
9
9
  spec.authors = ["Micke Lisinge"]
10
10
  spec.email = ["hi@micke.me"]
11
- spec.description = %q{ActiveModel validation for email. Including MX lookup and disposable email blacklist}
12
- spec.summary = %q{ActiveModel validation for email. Including MX lookup and disposable email blacklist}
11
+ spec.description = %q{ActiveModel validation for email. Including MX lookup and disposable email deny list}
12
+ spec.summary = %q{ActiveModel validation for email. Including MX lookup and disposable email deny list}
13
13
  spec.homepage = "https://github.com/micke/valid_email2"
14
14
  spec.license = "MIT"
15
15
 
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: 5.2.6
4
+ version: 5.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: 2024-08-10 00:00:00.000000000 Z
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.2'
125
125
  description: ActiveModel validation for email. Including MX lookup and disposable
126
- email blacklist
126
+ email deny list
127
127
  email:
128
128
  - hi@micke.me
129
129
  executables: []
@@ -140,10 +140,11 @@ files:
140
140
  - LICENSE.txt
141
141
  - README.md
142
142
  - Rakefile
143
- - config/blacklisted_email_domains.yml
143
+ - config/deny_listed_email_domains.yml
144
144
  - config/disposable_email_domains.txt
145
145
  - gemfiles/activemodel6.gemfile
146
146
  - gemfiles/activemodel7.gemfile
147
+ - lib/helpers/deprecation_helper.rb
147
148
  - lib/valid_email2.rb
148
149
  - lib/valid_email2/address.rb
149
150
  - lib/valid_email2/email_validator.rb
@@ -178,7 +179,7 @@ rubygems_version: 3.5.3
178
179
  signing_key:
179
180
  specification_version: 4
180
181
  summary: ActiveModel validation for email. Including MX lookup and disposable email
181
- blacklist
182
+ deny list
182
183
  test_files:
183
184
  - spec/address_spec.rb
184
185
  - spec/benchmark_spec.rb
@@ -1 +0,0 @@
1
- - blacklisted-test.com