can_has_validations 1.7.0 → 1.8.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b019c7cb6040ee0139aaaeb3cac5e115cc144cf0b4fb8eef8a6182772704eeb3
|
4
|
+
data.tar.gz: 7b9cf22f18f2d29092f71c4eacbb26fafb3ea0bf667ae8cc4d203b80c84b9eff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3604c217ef68acdccc4db9e87309522223722a00f1ab74b6cffb03a67e75450d629168a1f32afcaaf0833d0761e9b9d98cffc23ac65a0473c978d2263381d7d8
|
7
|
+
data.tar.gz: 1458eb8d69395bf07d745a8b84308aed359f801fdf103577c789a99d4440667a65c8f655f5f21cede6b6c6f83a5dc450bcd9eccb45d7eb30c54ee393326ebdd7
|
@@ -1,38 +1,40 @@
|
|
1
1
|
# Ensure an attribute is generally formatted as an email.
|
2
2
|
# eg: validates :user_email, email: true
|
3
|
+
# validates :user_email, email: {allow_unicode: true}
|
3
4
|
|
4
5
|
require_relative 'hostname_validator'
|
5
6
|
|
6
7
|
module ActiveModel::Validations
|
7
8
|
class EmailValidator < ActiveModel::EachValidator
|
8
9
|
|
9
|
-
EMAIL_REGEXP = /\A([a-z0-9._+-]+)@((?:[
|
10
|
-
SEGMENT_REGEXP = /\A[a-z0-
|
11
|
-
LABEL_REGEXP =
|
10
|
+
EMAIL_REGEXP = /\A([a-z0-9._+-]+)@((?:[a-z0-9-]+\.)+[a-z]{2,})\z/i
|
11
|
+
SEGMENT_REGEXP = /\A[a-z0-9_+-]+\z/i
|
12
|
+
LABEL_REGEXP = %r{\A([a-zA-Z0-9]([a-zA-Z0-9-]+)?)?[a-zA-Z0-9]\z}
|
13
|
+
# HostnameValidator::LABEL_REGEXP minus _/
|
12
14
|
FINAL_LABEL_REGEXP = HostnameValidator::FINAL_LABEL_REGEXP
|
13
15
|
|
14
16
|
def validate_each(record, attribute, value)
|
15
|
-
unless email_valid?(value)
|
17
|
+
unless email_valid?(value, **options.slice(:allow_unicode))
|
16
18
|
record.errors.add(attribute, :invalid_email, **options.merge(value: value))
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def email_valid?(value)
|
22
|
+
def email_valid?(value, allow_unicode: false)
|
21
23
|
return unless value
|
22
|
-
recipient, domain = value.split('@', 2)
|
24
|
+
recipient, domain = value.to_s.split('@', 2)
|
23
25
|
is_valid = true
|
24
26
|
|
25
27
|
recipient ||= ''
|
26
28
|
is_valid &&= recipient.length <= 255
|
27
29
|
is_valid &&= recipient !~ /\.\./
|
28
|
-
is_valid &&= !recipient.starts_with?('.')
|
29
|
-
is_valid &&= !recipient.ends_with?('.')
|
30
|
+
is_valid &&= !recipient.starts_with?('.')
|
31
|
+
is_valid &&= !recipient.ends_with?('.')
|
30
32
|
recipient.split('.').each do |segment|
|
31
33
|
is_valid &&= segment =~ SEGMENT_REGEXP
|
32
34
|
end
|
33
35
|
|
34
36
|
domain ||= ''
|
35
|
-
if defined?(Addressable::IDNA)
|
37
|
+
if allow_unicode && defined?(Addressable::IDNA)
|
36
38
|
domain &&= Addressable::IDNA.to_ascii(domain)
|
37
39
|
end
|
38
40
|
labels = domain.split('.')
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# If the addressable gem is present, will automatically turn unicode domains
|
13
13
|
# into their punycode (xn--) equivalent. Otherwise, unicode characters will
|
14
14
|
# cause the validation to fail.
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# eg: validates :domain, hostname: true
|
17
17
|
# validates :domain, hostname: {allow_wildcard: true}
|
18
18
|
# allows '*.example.com'
|
@@ -52,7 +52,7 @@ module ActiveModel::Validations
|
|
52
52
|
if defined?(Addressable::IDNA)
|
53
53
|
value &&= Addressable::IDNA.to_ascii(value)
|
54
54
|
end
|
55
|
-
labels = value.split('.')
|
55
|
+
labels = value.split('.', -1)
|
56
56
|
|
57
57
|
is_valid = true
|
58
58
|
is_valid &&= value.length <= 255
|
data/test/dummy/log/test.log
CHANGED
@@ -1,22 +1,14 @@
|
|
1
|
-
[1m[
|
2
|
-
[1m[36mTRANSACTION (0.1ms)[0m [1m[36mbegin transaction[0m
|
1
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
3
2
|
---------------------------------
|
4
3
|
CanHasValidationsTest: test_truth
|
5
4
|
---------------------------------
|
6
5
|
[1m[36mTRANSACTION (0.0ms)[0m [1m[31mrollback transaction[0m
|
7
|
-
[1m[
|
8
|
-
[1m[36mTRANSACTION (0.1ms)[0m [1m[36mbegin transaction[0m
|
6
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
9
7
|
---------------------------------
|
10
8
|
CanHasValidationsTest: test_truth
|
11
9
|
---------------------------------
|
12
10
|
[1m[36mTRANSACTION (0.0ms)[0m [1m[31mrollback transaction[0m
|
13
|
-
[1m[
|
14
|
-
[1m[36mTRANSACTION (0.1ms)[0m [1m[36mbegin transaction[0m
|
15
|
-
---------------------------------
|
16
|
-
CanHasValidationsTest: test_truth
|
17
|
-
---------------------------------
|
18
|
-
[1m[36mTRANSACTION (0.0ms)[0m [1m[31mrollback transaction[0m
|
19
|
-
[1m[36mTRANSACTION (0.1ms)[0m [1m[36mbegin transaction[0m
|
11
|
+
[1m[36mTRANSACTION (0.0ms)[0m [1m[36mbegin transaction[0m
|
20
12
|
---------------------------------
|
21
13
|
CanHasValidationsTest: test_truth
|
22
14
|
---------------------------------
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_has_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '7.
|
22
|
+
version: '7.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '7.
|
32
|
+
version: '7.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,7 +119,6 @@ files:
|
|
119
119
|
- test/dummy/config/routes.rb
|
120
120
|
- test/dummy/config/storage.yml
|
121
121
|
- test/dummy/db/test.sqlite3
|
122
|
-
- test/dummy/log/development.log
|
123
122
|
- test/dummy/log/test.log
|
124
123
|
- test/dummy/public/404.html
|
125
124
|
- test/dummy/public/422.html
|
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
146
|
- !ruby/object:Gem::Version
|
148
147
|
version: '0'
|
149
148
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.4.10
|
151
150
|
signing_key:
|
152
151
|
specification_version: 4
|
153
152
|
summary: Assorted Rails 5.x-7.x validators
|
@@ -185,7 +184,6 @@ test_files:
|
|
185
184
|
- test/dummy/config/storage.yml
|
186
185
|
- test/dummy/config.ru
|
187
186
|
- test/dummy/db/test.sqlite3
|
188
|
-
- test/dummy/log/development.log
|
189
187
|
- test/dummy/log/test.log
|
190
188
|
- test/dummy/public/404.html
|
191
189
|
- test/dummy/public/422.html
|
@@ -1,8 +0,0 @@
|
|
1
|
-
DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
|
2
|
-
`legacy_connection_handling` to `false` in your application.
|
3
|
-
|
4
|
-
The new connection handling does not support `connection_handlers`
|
5
|
-
getter and setter.
|
6
|
-
|
7
|
-
Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
|
8
|
-
(called from require at script/rails:6)
|