validators 2.8.1 → 3.0.0
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 +4 -4
- data/.rubocop.yml +86 -0
- data/.travis.yml +12 -9
- data/Gemfile +2 -0
- data/Rakefile +10 -1
- data/bin/sync-disposable-hostnames +3 -3
- data/data/disposable.json +854 -4
- data/data/tld.json +2 -5
- data/lib/validators/constants.rb +9 -7
- data/lib/validators/disposable_hostnames.rb +4 -2
- data/lib/validators/hostname.rb +12 -10
- data/lib/validators/ip.rb +7 -3
- data/lib/validators/tld.rb +5 -2
- data/lib/validators/validates_cnpj_format_of.rb +6 -2
- data/lib/validators/validates_cpf_format_of.rb +6 -2
- data/lib/validators/validates_datetime.rb +23 -22
- data/lib/validators/validates_email_format_of.rb +4 -2
- data/lib/validators/validates_hostname_format_of.rb +2 -0
- data/lib/validators/validates_ip_address.rb +5 -1
- data/lib/validators/validates_ownership_of.rb +5 -1
- data/lib/validators/validates_ssh_private_key.rb +5 -5
- data/lib/validators/validates_ssh_public_key.rb +3 -1
- data/lib/validators/validates_url_format_of.rb +11 -5
- data/lib/validators/version.rb +6 -4
- data/lib/validators.rb +2 -0
- data/test/schema.rb +2 -0
- data/test/support/dates.rb +4 -2
- data/test/support/emails.rb +8 -6
- data/test/support/hostnames.rb +6 -4
- data/test/support/ips.rb +4 -2
- data/test/support/models.rb +2 -0
- data/test/support/urls.rb +8 -7
- data/test/test_helper.rb +21 -6
- data/test/validators/disposable_email_test.rb +2 -0
- data/test/validators/ip_test.rb +2 -0
- data/test/validators/validates_cnpj_format_of_test.rb +22 -7
- data/test/validators/validates_cpf_format_of_test.rb +22 -7
- data/test/validators/validates_datetime/after_option_test.rb +27 -1
- data/test/validators/validates_datetime/before_option_test.rb +2 -0
- data/test/validators/validates_datetime/defaults_test.rb +2 -0
- data/test/validators/validates_email_format_of_test.rb +2 -0
- data/test/validators/validates_hostname_format_of/with_tld_validation_test.rb +2 -0
- data/test/validators/validates_hostname_format_of/without_tld_validation_test.rb +7 -0
- data/test/validators/validates_ip_address/ipv4_test.rb +8 -0
- data/test/validators/validates_ip_address/ipv6_test.rb +2 -0
- data/test/validators/validates_ip_address_test.rb +2 -0
- data/test/validators/validates_ownership_of_test.rb +2 -0
- data/test/validators/validates_ssh_private_key/bits_test.rb +12 -8
- data/test/validators/validates_ssh_private_key/common_test.rb +22 -7
- data/test/validators/validates_ssh_private_key/dsa_test.rb +12 -8
- data/test/validators/validates_ssh_private_key/rsa_test.rb +12 -8
- data/test/validators/validates_ssh_public_key_test.rb +22 -7
- data/test/validators/validates_url_format_of/with_tld_validation_test.rb +2 -0
- data/test/validators/validates_url_format_of/without_tld_validation_test.rb +2 -0
- data/validators.gemspec +12 -7
- metadata +52 -10
data/data/tld.json
CHANGED
@@ -15,7 +15,6 @@
|
|
15
15
|
"accountant",
|
16
16
|
"accountants",
|
17
17
|
"aco",
|
18
|
-
"active",
|
19
18
|
"actor",
|
20
19
|
"ad",
|
21
20
|
"adac",
|
@@ -145,7 +144,6 @@
|
|
145
144
|
"bj",
|
146
145
|
"black",
|
147
146
|
"blackfriday",
|
148
|
-
"blanco",
|
149
147
|
"blockbuster",
|
150
148
|
"blog",
|
151
149
|
"bloomberg",
|
@@ -391,7 +389,6 @@
|
|
391
389
|
"engineer",
|
392
390
|
"engineering",
|
393
391
|
"enterprises",
|
394
|
-
"epost",
|
395
392
|
"epson",
|
396
393
|
"equipment",
|
397
394
|
"er",
|
@@ -1151,13 +1148,13 @@
|
|
1151
1148
|
"sony",
|
1152
1149
|
"soy",
|
1153
1150
|
"space",
|
1154
|
-
"spiegel",
|
1155
1151
|
"sport",
|
1156
1152
|
"spot",
|
1157
1153
|
"spreadbetting",
|
1158
1154
|
"sr",
|
1159
1155
|
"srl",
|
1160
1156
|
"srt",
|
1157
|
+
"ss",
|
1161
1158
|
"st",
|
1162
1159
|
"stada",
|
1163
1160
|
"staples",
|
@@ -1451,6 +1448,7 @@
|
|
1451
1448
|
"xn--mgbaakc7dvf",
|
1452
1449
|
"xn--mgbaam7a8h",
|
1453
1450
|
"xn--mgbab2bd",
|
1451
|
+
"xn--mgbah1a3hjkrd",
|
1454
1452
|
"xn--mgbai9azgqp6j",
|
1455
1453
|
"xn--mgbayh7gpa",
|
1456
1454
|
"xn--mgbb9fbpob",
|
@@ -1529,7 +1527,6 @@
|
|
1529
1527
|
"zara",
|
1530
1528
|
"zero",
|
1531
1529
|
"zip",
|
1532
|
-
"zippo",
|
1533
1530
|
"zm",
|
1534
1531
|
"zone",
|
1535
1532
|
"zuerich",
|
data/lib/validators/constants.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validators
|
2
|
-
EMAIL_FORMAT = /\A[a-z0-9]+([-._][a-z0-9]+)*(\+[^@]+)?@[a-z0-9]+([.-][a-z0-9]+)*\.[a-z]{2,}\z/i
|
3
|
-
MICROSOFT_EMAIL_FORMAT = /\A[\w][\w\d._-]*[\w\d_-]+(\+[\w\d]+)?@(hotmail|outlook).com\z/i
|
4
|
+
EMAIL_FORMAT = /\A[a-z0-9]+([-._][a-z0-9]+)*(\+[^@]+)?@[a-z0-9]+([.-][a-z0-9]+)*\.[a-z]{2,}\z/i.freeze
|
5
|
+
MICROSOFT_EMAIL_FORMAT = /\A[\w][\w\d._-]*[\w\d_-]+(\+[\w\d]+)?@(hotmail|outlook).com\z/i.freeze
|
4
6
|
|
5
7
|
# Source: https://github.com/henrik/validates_url_format_of
|
6
|
-
|
8
|
+
IPV4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/.freeze # 0-255
|
7
9
|
|
8
10
|
URL_FORMAT = %r[
|
9
11
|
\A
|
10
12
|
https?:// # http:// or https://
|
11
13
|
([^\s:@]+:[^\s:@]*@)? # optional username:pw@
|
12
14
|
( (([^\W_]+\.)*xn--)?[^\W_]+([-.][^\W_]+)*\.[a-z]{2,6}\.? | # domain (including Punycode/IDN)...
|
13
|
-
#{
|
15
|
+
#{IPV4_PART}(\.#{IPV4_PART}){3} ) # or IPv4
|
14
16
|
(:\d{1,5})? # optional port
|
15
17
|
([/?]\S*)? # optional /whatever or ?whatever
|
16
18
|
\z
|
17
|
-
]ixs
|
19
|
+
]ixs.freeze
|
18
20
|
|
19
21
|
URL_FORMAT_WITHOUT_TLD_VALIDATION = %r[
|
20
22
|
\A
|
21
23
|
https?:// # http:// or https://
|
22
24
|
([^\s:@]+:[^\s:@]*@)? # optional username:pw@
|
23
25
|
( (([^\W_]+\.)*xn--)?[^\W_]+([-.][^\W_]+)*\..{2,}\.? | # domain (including Punycode/IDN)...
|
24
|
-
#{
|
26
|
+
#{IPV4_PART}(\.#{IPV4_PART}){3} ) # or IPv4
|
25
27
|
(:\d{1,5})? # optional port
|
26
28
|
([/?]\S*)? # optional /whatever or ?whatever
|
27
29
|
\z
|
28
|
-
]ixs
|
30
|
+
]ixs.freeze
|
29
31
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validators
|
2
4
|
class DisposableHostnames
|
3
|
-
FILE_PATH = File.expand_path("
|
5
|
+
FILE_PATH = File.expand_path("../../data/disposable.json", __dir__)
|
4
6
|
|
5
7
|
def self.all
|
6
|
-
@
|
8
|
+
@all ||= JSON.parse(File.read(FILE_PATH))
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/validators/hostname.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validators
|
2
4
|
class Hostname
|
3
5
|
def self.valid?(host)
|
@@ -5,22 +7,22 @@ module Validators
|
|
5
7
|
uri = URI(host)
|
6
8
|
|
7
9
|
host.present? &&
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
uri.host.nil? &&
|
11
|
+
uri.scheme.nil? &&
|
12
|
+
uri.fragment.nil? &&
|
13
|
+
uri.query.nil? &&
|
14
|
+
uri.path == host &&
|
15
|
+
host.split(".").all? {|label| valid_label?(label) } &&
|
16
|
+
host.size <= 255 &&
|
17
|
+
Validators::TLD.host_with_valid_tld?(host)
|
16
18
|
rescue URI::InvalidURIError
|
17
19
|
false
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.valid_label?(label)
|
21
23
|
!label.start_with?("-") &&
|
22
|
-
|
23
|
-
|
24
|
+
!label.match(/\A\d+\z/) &&
|
25
|
+
label.match(/\A[a-z0-9-]{1,63}\z/i)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/validators/ip.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validators
|
2
4
|
module Ip
|
3
|
-
extend self
|
4
|
-
|
5
5
|
# Extracted from Ruby 1.8.7
|
6
6
|
def v4?(addr)
|
7
7
|
matches = addr.match(/\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/)
|
8
|
-
matches
|
8
|
+
matches&.captures&.all? {|i| i.to_i < 256 }
|
9
9
|
end
|
10
10
|
|
11
11
|
# Extracted from Ruby 1.8.7
|
@@ -25,5 +25,9 @@ module Validators
|
|
25
25
|
def valid?(addr)
|
26
26
|
v4?(addr) || v6?(addr)
|
27
27
|
end
|
28
|
+
|
29
|
+
module_function :v4?
|
30
|
+
module_function :v6?
|
31
|
+
module_function :valid?
|
28
32
|
end
|
29
33
|
end
|
data/lib/validators/tld.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validators
|
2
4
|
class TLD
|
3
|
-
FILE_PATH = File.expand_path("
|
5
|
+
FILE_PATH = File.expand_path("../../data/tld.json", __dir__)
|
4
6
|
|
5
7
|
def self.all
|
6
|
-
@
|
8
|
+
@all ||= JSON.parse(File.read(FILE_PATH))
|
7
9
|
end
|
8
10
|
|
9
11
|
def self.host_with_valid_tld?(host)
|
10
12
|
return false if host.split(".").size == 1
|
13
|
+
|
11
14
|
valid? host[/\.([^.]+)$/, 1].to_s.downcase
|
12
15
|
end
|
13
16
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class CnpjValidator < EachValidator
|
@@ -6,7 +8,9 @@ module ActiveModel
|
|
6
8
|
return if value.nil? && options[:allow_nil]
|
7
9
|
return if CNPJ.valid?(value)
|
8
10
|
|
9
|
-
record.errors.add(
|
11
|
+
record.errors.add(
|
12
|
+
attribute,
|
13
|
+
:invalid_cnpj,
|
10
14
|
message: options[:message],
|
11
15
|
value: value
|
12
16
|
)
|
@@ -24,7 +28,7 @@ module ActiveModel
|
|
24
28
|
require "cnpj"
|
25
29
|
validates_with CnpjValidator, _merge_attributes(attr_names)
|
26
30
|
rescue LoadError
|
27
|
-
|
31
|
+
raise "cpf_cnpj is not part of the bundle. Add it to Gemfile."
|
28
32
|
end
|
29
33
|
|
30
34
|
alias_method :validates_cnpj, :validates_cnpj_format_of
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class CpfValidator < EachValidator
|
@@ -6,7 +8,9 @@ module ActiveModel
|
|
6
8
|
return if value.nil? && options[:allow_nil]
|
7
9
|
return if CPF.valid?(value)
|
8
10
|
|
9
|
-
record.errors.add(
|
11
|
+
record.errors.add(
|
12
|
+
attribute,
|
13
|
+
:invalid_cpf,
|
10
14
|
message: options[:message],
|
11
15
|
value: value
|
12
16
|
)
|
@@ -24,7 +28,7 @@ module ActiveModel
|
|
24
28
|
require "cpf"
|
25
29
|
validates_with CpfValidator, _merge_attributes(attr_names)
|
26
30
|
rescue LoadError
|
27
|
-
|
31
|
+
raise "cpf_cnpj is not part of the bundle. Add it to Gemfile."
|
28
32
|
end
|
29
33
|
|
30
34
|
alias_method :validates_cpf, :validates_cpf_format_of
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class DatetimeValidator < EachValidator
|
4
6
|
def date?(value)
|
5
|
-
value.
|
7
|
+
value.is_a?(Date) || value.is_a?(Time)
|
6
8
|
end
|
7
9
|
|
8
10
|
def validate_each(record, attribute, value)
|
@@ -18,37 +20,36 @@ module ActiveModel
|
|
18
20
|
)
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
return unless date?(value)
|
24
|
+
|
25
|
+
validate_after_option(record, attribute, value)
|
26
|
+
validate_before_option(record, attribute, value)
|
25
27
|
end
|
26
28
|
|
27
|
-
private
|
28
|
-
def date_for(record, value, option)
|
29
|
+
private def date_for(record, value, option)
|
29
30
|
date = case option
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
when :today
|
32
|
+
Date.today
|
33
|
+
when :now
|
34
|
+
Time.now
|
35
|
+
when Time, Date, DateTime, ActiveSupport::TimeWithZone
|
36
|
+
option
|
37
|
+
when Proc
|
38
|
+
option.call(record)
|
39
|
+
else
|
40
|
+
record.__send__(option) if record.respond_to?(option)
|
41
|
+
end
|
41
42
|
|
42
|
-
if date.
|
43
|
+
if date.is_a?(Time)
|
43
44
|
value = value.to_time
|
44
|
-
elsif date.
|
45
|
+
elsif date.is_a?(Date)
|
45
46
|
value = value.to_date
|
46
47
|
end
|
47
48
|
|
48
49
|
[date, value]
|
49
50
|
end
|
50
51
|
|
51
|
-
def validate_after_option(record, attribute, value)
|
52
|
+
private def validate_after_option(record, attribute, value)
|
52
53
|
return unless options[:after]
|
53
54
|
|
54
55
|
date, value = date_for(record, value, options[:after])
|
@@ -64,7 +65,7 @@ module ActiveModel
|
|
64
65
|
)
|
65
66
|
end
|
66
67
|
|
67
|
-
def validate_before_option(record, attribute, value)
|
68
|
+
private def validate_before_option(record, attribute, value)
|
68
69
|
return unless options[:before]
|
69
70
|
|
70
71
|
date, value = date_for(record, value, options[:before])
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class EmailValidator < EachValidator
|
4
|
-
AT_SIGN = "@"
|
6
|
+
AT_SIGN = "@"
|
5
7
|
|
6
8
|
def validate_each(record, attribute, value)
|
7
9
|
allow_disposable = options.fetch(:disposable, false)
|
@@ -39,7 +41,7 @@ module ActiveModel
|
|
39
41
|
)
|
40
42
|
end
|
41
43
|
|
42
|
-
def validate_disposable_email(record, attribute, value,
|
44
|
+
def validate_disposable_email(record, attribute, value, _options)
|
43
45
|
hostname = value.to_s.split(AT_SIGN).last.to_s.downcase
|
44
46
|
|
45
47
|
return unless Validators::DisposableHostnames.all.include?(hostname)
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class IpAddressValidator < EachValidator
|
6
|
+
PROTOCOL_OPTIONS = %i[v4 v6].freeze
|
7
|
+
|
4
8
|
def validate_each(record, attribute, value)
|
5
9
|
return if value.blank? && options[:allow_blank]
|
6
10
|
return if value.nil? && options[:allow_nil]
|
@@ -30,7 +34,7 @@ module ActiveModel
|
|
30
34
|
|
31
35
|
def check_validity!
|
32
36
|
return unless options.key?(:only)
|
33
|
-
return if
|
37
|
+
return if PROTOCOL_OPTIONS.include?(options[:only])
|
34
38
|
|
35
39
|
raise ArgumentError, ":only accepts a symbol that can be either :v6 or :v4"
|
36
40
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class OwnershipValidator < EachValidator
|
6
|
+
WITH_OPTIONS = %w[String Symbol].freeze
|
7
|
+
|
4
8
|
def validate_each(record, attribute, value)
|
5
9
|
owner = record.send(options[:with])
|
6
10
|
actual_owner = value ? value.send(options[:with]) : nil
|
@@ -17,7 +21,7 @@ module ActiveModel
|
|
17
21
|
|
18
22
|
def check_validity!
|
19
23
|
raise ArgumentError, ":with is required" unless options.key?(:with)
|
20
|
-
raise ArgumentError, ":with option must be a string or a symbol" unless
|
24
|
+
raise ArgumentError, ":with option must be a string or a symbol" unless WITH_OPTIONS.include?(options[:with].class.name)
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class SshPrivateKeyValidator < EachValidator
|
@@ -17,9 +19,7 @@ module ActiveModel
|
|
17
19
|
)
|
18
20
|
end
|
19
21
|
|
20
|
-
private
|
21
|
-
|
22
|
-
def validate_type(record, attribute, sshkey)
|
22
|
+
private def validate_type(record, attribute, sshkey)
|
23
23
|
return unless options[:type]
|
24
24
|
|
25
25
|
valid = [options[:type]].flatten.compact.map(&:to_s).include?(sshkey.type)
|
@@ -34,7 +34,7 @@ module ActiveModel
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
-
def validate_bits(record, attribute, sshkey)
|
37
|
+
private def validate_bits(record, attribute, sshkey)
|
38
38
|
return unless options[:bits]
|
39
39
|
return if sshkey.bits >= options[:bits].to_i
|
40
40
|
|
@@ -59,7 +59,7 @@ module ActiveModel
|
|
59
59
|
require "sshkey"
|
60
60
|
validates_with SshPrivateKeyValidator, _merge_attributes(attr_names)
|
61
61
|
rescue LoadError
|
62
|
-
|
62
|
+
raise "sshkey is not part of the bundle. Add it to Gemfile."
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class SshPublicKeyValidator < EachValidator
|
@@ -26,7 +28,7 @@ module ActiveModel
|
|
26
28
|
require "sshkey"
|
27
29
|
validates_with SshPublicKeyValidator, _merge_attributes(attr_names)
|
28
30
|
rescue LoadError
|
29
|
-
|
31
|
+
raise "sshkey is not part of the bundle. Add it to Gemfile."
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveModel
|
2
4
|
module Validations
|
3
5
|
class UrlValidator < EachValidator
|
@@ -16,18 +18,22 @@ module ActiveModel
|
|
16
18
|
|
17
19
|
def url?(url)
|
18
20
|
uri = URI(url)
|
19
|
-
regex = options[:tld]
|
20
|
-
|
21
|
+
regex = if options[:tld]
|
22
|
+
Validators::URL_FORMAT_WITHOUT_TLD_VALIDATION
|
23
|
+
else
|
24
|
+
Validators::URL_FORMAT
|
25
|
+
end
|
21
26
|
|
22
|
-
uri.
|
23
|
-
|
24
|
-
|
27
|
+
uri.is_a?(URI::HTTP) &&
|
28
|
+
url.match(regex) &&
|
29
|
+
valid_tld?(uri.host)
|
25
30
|
rescue URI::InvalidURIError
|
26
31
|
false
|
27
32
|
end
|
28
33
|
|
29
34
|
def valid_tld?(host)
|
30
35
|
return true unless options[:tld]
|
36
|
+
|
31
37
|
Validators::TLD.host_with_valid_tld?(host)
|
32
38
|
end
|
33
39
|
end
|
data/lib/validators/version.rb
CHANGED
data/lib/validators.rb
CHANGED
data/test/schema.rb
CHANGED
data/test/support/dates.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
VALID_DATES = [
|
2
4
|
"2010-04-26",
|
3
5
|
"2010-04-26 23:59:00",
|
@@ -9,11 +11,11 @@ VALID_DATES = [
|
|
9
11
|
Date.today,
|
10
12
|
DateTime.now,
|
11
13
|
Time.zone.now
|
12
|
-
]
|
14
|
+
].freeze
|
13
15
|
|
14
16
|
INVALID_DATES = [
|
15
17
|
"invalid",
|
16
18
|
nil,
|
17
19
|
"",
|
18
20
|
"4/26"
|
19
|
-
]
|
21
|
+
].freeze
|
data/test/support/emails.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
INVALID_EMAILS = [
|
2
4
|
"invalid@example-com",
|
3
5
|
# period can not start local part
|
@@ -19,12 +21,12 @@ INVALID_EMAILS = [
|
|
19
21
|
"invalid@example.",
|
20
22
|
# from http://tools.ietf.org/html/rfc3696, page 5
|
21
23
|
# corrected in http://www.rfc-editor.org/errata_search.php?rfc=3696
|
22
|
-
|
24
|
+
"Fred\ Bloggs_@example.com",
|
23
25
|
'Abc\@def+@example.com',
|
24
26
|
'Joe.\\Blow@example.com',
|
25
|
-
|
26
|
-
|
27
|
-
]
|
27
|
+
"invalid.@hotmail.com",
|
28
|
+
"invalid.@outlook.com"
|
29
|
+
].freeze
|
28
30
|
|
29
31
|
VALID_EMAILS = [
|
30
32
|
"valid@somedomain.com",
|
@@ -46,5 +48,5 @@ VALID_EMAILS = [
|
|
46
48
|
"valid_-_-_-_-_-_@hotmail.com",
|
47
49
|
"valid_-_-_-_-_-_@outlook.com",
|
48
50
|
"sub_total-5+8@hotmail.com",
|
49
|
-
"sub_total-5+8@outlook.com"
|
50
|
-
]
|
51
|
+
"sub_total-5+8@outlook.com"
|
52
|
+
].freeze
|
data/test/support/hostnames.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
VALID_HOSTNAMES = %w[
|
2
4
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com
|
3
5
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com
|
4
6
|
a-b.com
|
@@ -7,12 +9,12 @@ VALID_HOSTNAMES = %W[
|
|
7
9
|
123a.com
|
8
10
|
ABC123.com
|
9
11
|
123ABC.com
|
10
|
-
]
|
12
|
+
].freeze
|
11
13
|
|
12
14
|
INVALID_HOSTNAMES = %W[
|
13
15
|
192.168.42.42
|
14
16
|
a..com
|
15
|
-
#{'a'*64}.com
|
17
|
+
#{'a' * 64}.com
|
16
18
|
http://example.com
|
17
19
|
https://example.com
|
18
20
|
example.com?a=1
|
@@ -23,4 +25,4 @@ INVALID_HOSTNAMES = %W[
|
|
23
25
|
example.1234.com
|
24
26
|
example_domain.com
|
25
27
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com
|
26
|
-
]
|
28
|
+
].freeze
|
data/test/support/ips.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
VALID_IPV4 = [
|
2
4
|
"192.168.1.1",
|
3
5
|
"64.233.163.104",
|
4
6
|
"127.0.0.1",
|
5
7
|
"0.0.0.0"
|
6
|
-
]
|
8
|
+
].freeze
|
7
9
|
|
8
10
|
VALID_IPV6 = [
|
9
11
|
"FE80:0000:0000:0000:0202:B3FF:FE1E:8329",
|
@@ -17,4 +19,4 @@ VALID_IPV6 = [
|
|
17
19
|
"3ffe:1900:4545:3:200:f8ff:fe21:67cf",
|
18
20
|
"fe80:0:0:0:200:f8ff:fe21:67cf",
|
19
21
|
"fe80::200:f8ff:fe21:67cf"
|
20
|
-
]
|
22
|
+
].freeze
|
data/test/support/models.rb
CHANGED
data/test/support/urls.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
VALID_URLS = [
|
3
4
|
"http://example.com",
|
4
5
|
"http://example.com/",
|
@@ -17,14 +18,14 @@ VALID_URLS = [
|
|
17
18
|
"http://1.2.3.4:80",
|
18
19
|
"HttP://example.com",
|
19
20
|
"https://example.com",
|
20
|
-
# "http://räksmörgås.nu",
|
21
|
-
"http://xn--rksmrgs-5wao1o.nu",
|
21
|
+
# "http://räksmörgås.nu", # IDN
|
22
|
+
"http://xn--rksmrgs-5wao1o.nu", # Punycode
|
22
23
|
"http://www.xn--rksmrgs-5wao1o.nu",
|
23
24
|
"http://foo.bar.xn--rksmrgs-5wao1o.nu",
|
24
|
-
"http://example.xy",
|
25
|
-
"http://example.com.",
|
25
|
+
"http://example.xy", # Only valid TLD
|
26
|
+
"http://example.com.", # Explicit TLD root period
|
26
27
|
"http://example.com./foo"
|
27
|
-
]
|
28
|
+
].freeze
|
28
29
|
|
29
30
|
INVALID_URLS = [
|
30
31
|
"url",
|
@@ -40,4 +41,4 @@ INVALID_URLS = [
|
|
40
41
|
"http://example",
|
41
42
|
"http://example.c",
|
42
43
|
"http://example.toolongtld"
|
43
|
-
]
|
44
|
+
].freeze
|