can_has_validations 1.7.0 → 1.8.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: bb51b71bb23aabfeb3e1bde9ad0f03119d4011d60c7117971c606266eb0c477a
4
- data.tar.gz: 5b101d95e237b874ff096f9658c064709aef19228c3444f6ed6878fb1f5cc1c5
3
+ metadata.gz: c78f8e5cbb5c2bd034070fad41bbaf78b622430b2c0546b6cf2cb22f05fe0d93
4
+ data.tar.gz: e852f21850a91d4a0f348b96b913c315de7d663d812ac05b30f16917b216ad5a
5
5
  SHA512:
6
- metadata.gz: 82e3dc6177df9d32216bbefbbfeef97ccb4bebf22d5b8431c9d59393fd619f2d465b52f3c26eb84c551f35c154279e54c5689d595e699de0b65d211bc115c0ef
7
- data.tar.gz: fe709a9a7225cf2ea6eb7828c4d741b11c07181a32710d394972ddb424bc282d44d9f163388451671577ff0ebf96c28b3921f46d60b63e61f8be2384a0702e08
6
+ metadata.gz: ef126f2bd28db8947e189adef8572ca63d3cd964ab19732fd1291d49315c703b0f386793aeb2df22c4cea97ef195be9b6e6affacb91a49748f0df9cc05152cc3
7
+ data.tar.gz: 920a6ca45c368c4e3ddd077018b0ea67bb3bc11a46ca0855480077d3e62c8c5ccccbb6b55da1fbf99b3b727d9408f264b3744d6f938b9e6db1bfef390ff25434
@@ -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._+-]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
10
- SEGMENT_REGEXP = /\A[a-z0-9+_-]+\z/i
11
- LABEL_REGEXP = HostnameValidator::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('.')
@@ -1,3 +1,3 @@
1
1
  module CanHasValidations
2
- VERSION = '1.7.0'
2
+ VERSION = '1.8.0'
3
3
  end
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.7.0
4
+ version: 1.8.0
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-01-20 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails