email_validator 2.2.3 → 2.2.4

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
  SHA256:
3
- metadata.gz: 46bd723714c6aa3a844e584e986e5989920b6d3f212a44d800183d118c561cb7
4
- data.tar.gz: bb58e5bf862c4be796e3ce59727dcf3fd2e28267e7c6077014f01d25dc841580
3
+ metadata.gz: c6952edf85fc0eafbe159b4a3b812731c81361ee0a15f22927e270a3eb885c9d
4
+ data.tar.gz: 8b5a56e059f652f1822c93cbcec0be9da23842433e9c7e5f97478496ba888ff9
5
5
  SHA512:
6
- metadata.gz: 2ece91a44bd82bd79c5484a17729996731787148b6813af0c4e41804715242a9cbfb4c0d661b08e0c904753dd59f23560d11aed7bf9044986802445e36f69438
7
- data.tar.gz: 1b91bf21ce112f86f9b97138573d20fe14b67f075935136c3b19a620f155d50c5d5cf5ff9566e4c101429b8d7ce80ccb80709a2a15eeb07f4caeaac34f2b86b0
6
+ metadata.gz: 158307d4196989b8d73872fa91c302ee9eab174b25f0686f3d61fe395796fa0b8e6c1c08185a4accf6c9581e23ba66bbebb8e3e8dc46b7ded935ed80a2484b53
7
+ data.tar.gz: 7f9ccf405a9bcf08d809fa58819d9e6d8489871a52020115802f3c755eddc3962b3533928f8f7c40e8122b055ad185c6f72cf1878ad6c920ba1b86872c0362a8
data/CHANGELOG.md CHANGED
@@ -5,6 +5,31 @@ This file is used to list changes made in `email_validator`.
5
5
  All notable changes to this project will be documented in this file.
6
6
  This project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## 2.2.4 (2022-11-09)
9
+
10
+ * [karlwilbur] - Remove Ruby 2.4 from tested versions; add Ruby 3.0 and 3.1 to tested versions
11
+ * [karlwilbur] - Fix issue where `domain: ''` wasn't requiring empty domain
12
+ * [karlwilbur] - Remove checks for double hyphens (fixes [#87](https://github.com/K-and-R/email_validator/issues/87))
13
+ * [dependabot] - Security updates
14
+ - [#89](https://github.com/K-and-R/email_validator/pull/89)
15
+ + Bump `minimist` from `1.2.5` to `1.2.7`
16
+ - [#86](https://github.com/K-and-R/email_validator/pull/86)
17
+ + Bump `node-fetch` from `2.6.1` to `2.6.7`
18
+ + Add `whatwg-url` at `5.0.0`
19
+ + Add `tr46` at `0.0.3`
20
+ + Add `webidl-conversions` at `3.0.0`
21
+ - [#80](https://github.com/K-and-R/email_validator/pull/80)
22
+ + Bump `tar` from `6.0.5` to `6.1.11`
23
+ + Bump `minipass` from `3.1.3` to `3.1.5`
24
+ - [#79](https://github.com/K-and-R/email_validator/pull/79)
25
+ + Bump `path-parse` from `1.0.6` to `1.0.7`
26
+ - [#76](https://github.com/K-and-R/email_validator/pull/76)
27
+ + Bump `lodash` from `4.17.20` to `4.17.21`
28
+ - [#75](https://github.com/K-and-R/email_validator/pull/75)
29
+ + Bump `hosted-git-info` from `2.8.8` to `2.8.9`
30
+ * [msands] - Fix URL in `README.md` [#81](https://github.com/K-and-R/email_validator/pull/81)
31
+ * [kerolloz] - Fix typo in `README.md` [#73](https://github.com/K-and-R/email_validator/pull/73)
32
+
8
33
  ## 2.2.3 (2021-04-05)
9
34
 
10
35
  * [karlwilbur] - Fix regexp for numeric domains (fixes [#72](https://github.com/K-and-R/email_validator/issues/72))
@@ -12,8 +37,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
12
37
  - [karlwilbur] - Fix specs for numeric-only domains labels (should be considered valid)
13
38
  - [karlwilbur] - Add checks for numeric-only TLDs in tests (should be considered invalid)
14
39
  - [karlwilbur] - Add tests to ensure that `regexp` returns expected value
15
- - [karlwilbur] - Add checks for double dash in domain (should be considered invalid)
16
- - [karlwilbur] - Add `EmailValidator::Error` class, raise `EmailValidator::Error` when invalid `mode`
40
+ * [karlwilbur] - Add checks for double dash in domain (should be considered invalid)
41
+ * [karlwilbur] - Add `EmailValidator::Error` class, raise `EmailValidator::Error` when invalid `mode`
17
42
 
18
43
  ## 2.2.2 (2020-12-10)
19
44
 
data/README.md CHANGED
@@ -14,7 +14,7 @@ Formerly found at: <https://github.com/balexand/email_validator>
14
14
 
15
15
  The default validation provided by this gem (the `:loose` configuration option)
16
16
  is extremely loose. It just checks that there's an `@` with something before and
17
- after it without any whitespace. See [this article by David Gilbertson](https://hackernoon.com/the-100-correct-way-to-validate-email-addresses-7c4818f24643)
17
+ after it without any whitespace. See [this article by David Gilbertson](https://medium.com/hackernoon/the-100-correct-way-to-validate-email-addresses-7c4818f24643)
18
18
  for an explanation of why.
19
19
 
20
20
  We understand that many use cases require an increased level of validation. This
@@ -68,7 +68,7 @@ Default configuration can be overridden by setting options in `config/initialize
68
68
 
69
69
  ```ruby
70
70
  if defined?(EmailValidator)
71
- # To completly override the defaults
71
+ # To completely override the defaults
72
72
  EmailValidator.default_options = {
73
73
  allow_nil: false,
74
74
  domain: nil,
@@ -27,6 +27,8 @@ class EmailValidator < ActiveModel::EachValidator
27
27
  options = parse_options(options)
28
28
  return true if value.nil? && options[:allow_nil] == true
29
29
  return false if value.nil?
30
+ # quickly fail if domain is required but doesn't match
31
+ return false unless options[:domain].nil? || value[/^.*@#{regexp_safe_domain(options)}$/]
30
32
  !!(value =~ regexp(options))
31
33
  end
32
34
 
@@ -94,7 +96,6 @@ class EmailValidator < ActiveModel::EachValidator
94
96
 
95
97
  def host_label_pattern
96
98
  "#{label_is_correct_length}" \
97
- "#{label_contains_no_more_than_one_consecutive_hyphen}" \
98
99
  "#{alnum}(?:#{alnumhy}{,61}#{alnum})?"
99
100
  end
100
101
 
@@ -123,10 +124,6 @@ class EmailValidator < ActiveModel::EachValidator
123
124
  '(?=.{1,255}$)'
124
125
  end
125
126
 
126
- def label_contains_no_more_than_one_consecutive_hyphen
127
- '(?!.*?--.*$)'
128
- end
129
-
130
127
  def atom_char
131
128
  # The `atext` spec
132
129
  # We are looking at this without whitespace; no whitespace support here
@@ -139,7 +136,7 @@ class EmailValidator < ActiveModel::EachValidator
139
136
  end
140
137
 
141
138
  def domain_part_pattern(options)
142
- return options[:domain].sub(/\./, '\.') if options[:domain].present?
139
+ return regexp_safe_domain(options) unless options[:domain].nil?
143
140
  return fqdn_pattern if options[:require_fqdn]
144
141
  "#{domain_part_is_correct_length}(?:#{address_literal}|(?:#{host_label_pattern}\\.)*#{tld_label_pattern})"
145
142
  end
@@ -155,6 +152,10 @@ class EmailValidator < ActiveModel::EachValidator
155
152
  options[:require_fqdn] = true if options[:require_fqdn].nil? && options[:mode] == :strict
156
153
  default_options.merge(options)
157
154
  end
155
+
156
+ def regexp_safe_domain(options)
157
+ options[:domain].sub(/\./, '\.')
158
+ end
158
159
  end
159
160
 
160
161
  def validate_each(record, attribute, value)
@@ -52,6 +52,18 @@ class NonFqdnRfcUser < TestModel
52
52
  validates :email, :email => { :require_fqdn => false, :mode => :rfc }
53
53
  end
54
54
 
55
+ class RequireFqdnWithEmptyDomainUser < TestModel
56
+ validates :email_address, :email => { :require_fqdn => true, :domain => '' }
57
+ end
58
+
59
+ class RequireEmptyDomainStrictUser < TestModel
60
+ validates :email_address, :email => { :require_fqdn => true, :domain => '', :mode => :strict }
61
+ end
62
+
63
+ class RequireEmptyDomainRfcUser < TestModel
64
+ validates :email_address, :email => { :require_fqdn => true, :domain => '', :mode => :rfc }
65
+ end
66
+
55
67
  class DefaultUserWithMessage < TestModel
56
68
  validates :email_address, :email => { :message => 'is not looking very good!' }
57
69
  end
@@ -147,7 +159,9 @@ RSpec.describe EmailValidator do
147
159
  'john.doe@2020.a-z.com',
148
160
  'john.doe@2020.a2z.com',
149
161
  'john.doe@2020.12345a6789.com',
150
- 'jonh.doe@163.com'
162
+ 'jonh.doe@163.com',
163
+ 'test@umläut.com', # non-ASCII
164
+ 'test@xn--umlut-ira.com' # ASCII-compatibale encoding of non-ASCII
151
165
  ]).flatten.each do |email|
152
166
  context 'when using defaults' do
153
167
  it "'#{email}' should be valid" do
@@ -477,7 +491,6 @@ RSpec.describe EmailValidator do
477
491
  'host-beginning-with-dot@.example.com',
478
492
  'domain-beginning-with-dash@-example.com',
479
493
  'domain-ending-with-dash@example-.com',
480
- 'domain-contains-double-dash@foo--example.com',
481
494
  'the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.dev',
482
495
  "domain-too-long@t#{".#{'o' * 63}" * 5}.long",
483
496
  "user@example.com<script>alert('hello')</script>"
@@ -727,7 +740,7 @@ RSpec.describe EmailValidator do
727
740
  end
728
741
 
729
742
  context 'when in `:strict` mode' do
730
- it "#{email.strip} in a model should be valid" do
743
+ it "#{email.strip} in a model should not be valid" do
731
744
  expect(StrictUser.new(:email => email)).not_to be_valid
732
745
  end
733
746
 
@@ -764,6 +777,68 @@ RSpec.describe EmailValidator do
764
777
  end
765
778
  end
766
779
 
780
+ context 'when `require_fqdn` is explicitly enabled with a blank domain' do
781
+ let(:opts) { { :require_fqdn => true, :domain => '' } }
782
+
783
+ context 'when given a email containing any domain' do
784
+ let(:email) { 'someuser@somehost' }
785
+
786
+ context 'when using defaults' do
787
+ it 'is not valid in a model' do
788
+ expect(RequireFqdnWithEmptyDomainUser.new(:email => email)).not_to be_valid
789
+ end
790
+
791
+ it 'is not using EmailValidator.valid?' do
792
+ expect(described_class).not_to be_valid(email, opts)
793
+ end
794
+
795
+ it 'is invalid using EmailValidator.invalid?' do
796
+ expect(described_class).to be_invalid(email, opts)
797
+ end
798
+
799
+ it 'does not match the regexp' do
800
+ expect(!!(email =~ described_class.regexp(opts))).to be(false)
801
+ end
802
+ end
803
+
804
+ context 'when in `:strict` mode' do
805
+ it 'is not valid in a model' do
806
+ expect(RequireEmptyDomainStrictUser.new(:email => email)).not_to be_valid
807
+ end
808
+
809
+ it 'is not using EmailValidator.valid?' do
810
+ expect(described_class).not_to be_valid(email, opts.merge({ :mode => :strict }))
811
+ end
812
+
813
+ it 'is invalid using EmailValidator.invalid?' do
814
+ expect(described_class).to be_invalid(email, opts.merge({ :mode => :strict }))
815
+ end
816
+
817
+ it 'does not match the regexp' do
818
+ expect(!!(email =~ described_class.regexp(opts.merge({ :mode => :strict })))).to be(false)
819
+ end
820
+ end
821
+
822
+ context 'when in `:rfc` mode' do
823
+ it 'is not valid in a model' do
824
+ expect(RequireEmptyDomainRfcUser.new(:email => email)).not_to be_valid
825
+ end
826
+
827
+ it 'is not using EmailValidator.valid?' do
828
+ expect(described_class).not_to be_valid(email, opts.merge({ :mode => :rfc }))
829
+ end
830
+
831
+ it 'is invalid using EmailValidator.invalid?' do
832
+ expect(described_class).to be_invalid(email, opts.merge({ :mode => :rfc }))
833
+ end
834
+
835
+ it 'does not match the regexp' do
836
+ expect(!!(email =~ described_class.regexp(opts.merge({ :mode => :rfc })))).to be(false)
837
+ end
838
+ end
839
+ end
840
+ end
841
+
767
842
  context 'when `require_fqdn` is explicitly disabled' do
768
843
  let(:opts) { { :require_fqdn => false } }
769
844
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Alexander
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-04-05 00:00:00.000000000 Z
12
+ date: 2022-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.1.4
64
+ rubygems_version: 3.2.15
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: An email validator for Rails 3+.