validators 2.4.1 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/validators.rb +1 -0
- data/lib/validators/tld.rb +18 -0
- data/lib/validators/validates_hostname_format_of.rb +1 -4
- data/lib/validators/validates_url_format_of.rb +1 -9
- data/lib/validators/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/validators/validates_hostname_format_of_spec.rb +5 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8b6da51895c47e9292d6a9f3e69e1344f048b9e
|
4
|
+
data.tar.gz: 00ce9db1e34727a6e1dd45d0c1664555a75de332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a95bfe1cd0d18157e457c349e47712b486980c75dfb31caf92e7a7ec7ee45bfe824807a35b0acdcc682c6bf3ad821153d4789cda1fe59224df9deba13528f3c2
|
7
|
+
data.tar.gz: d0d92d572381475e0c252bdafe45f3fc2f71c9cf98d5d553081ef9be9027ba8a251a14ca2298655d6584bca98afec13320ae574fc1ffee902fbceb424726c4c2
|
data/Gemfile.lock
CHANGED
data/lib/validators.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Validators
|
2
|
+
class TLD
|
3
|
+
TLD_FILE_PATH = File.expand_path('../../../data/tld.txt', __FILE__)
|
4
|
+
|
5
|
+
def self.all
|
6
|
+
@tld ||= File.read(TLD_FILE_PATH).lines.map(&:chomp)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.host_with_valid_tld?(host)
|
10
|
+
return false if host.split('.').size == 1
|
11
|
+
valid? host[/\.([^.]+)$/, 1].to_s.downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.valid?(tld)
|
15
|
+
all.include?(tld)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -38,10 +38,7 @@ module ActiveModel
|
|
38
38
|
|
39
39
|
def valid_tld?(host)
|
40
40
|
return true unless options[:tld]
|
41
|
-
|
42
|
-
|
43
|
-
tld = host[/\.(.*?)$/, 1].to_s.downcase
|
44
|
-
UrlValidator.tlds.include?(tld)
|
41
|
+
Validators::TLD.host_with_valid_tld?(host)
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
@@ -1,12 +1,6 @@
|
|
1
1
|
module ActiveModel
|
2
2
|
module Validations
|
3
3
|
class UrlValidator < EachValidator
|
4
|
-
TLD_FILE_PATH = File.expand_path('../../../data/tld.txt', __FILE__)
|
5
|
-
|
6
|
-
def self.tlds
|
7
|
-
@tld ||= File.read(TLD_FILE_PATH).lines.map(&:chomp)
|
8
|
-
end
|
9
|
-
|
10
4
|
def validate_each(record, attribute, value)
|
11
5
|
return if value.blank? && options[:allow_blank]
|
12
6
|
return if value.nil? && options[:allow_nil]
|
@@ -32,9 +26,7 @@ module ActiveModel
|
|
32
26
|
|
33
27
|
def valid_tld?(host)
|
34
28
|
return true unless options[:tld]
|
35
|
-
|
36
|
-
|
37
|
-
self.class.tlds.include?(tld)
|
29
|
+
Validators::TLD.host_with_valid_tld?(host)
|
38
30
|
end
|
39
31
|
end
|
40
32
|
|
data/lib/validators/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,7 @@ require "validators"
|
|
7
7
|
require "active_support/all"
|
8
8
|
|
9
9
|
Time.zone = "America/Sao_Paulo"
|
10
|
-
TLDs =
|
10
|
+
TLDs = Validators::TLD.all.sample(100)
|
11
11
|
|
12
12
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
13
13
|
|
@@ -18,6 +18,11 @@ describe ".validates_hostname_format_of" do
|
|
18
18
|
expect(server).to be_valid
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
it "accepts example.com.br" do
|
23
|
+
server = ServerWithTLD.new("example.com.br")
|
24
|
+
expect(server).to be_valid
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
context "without TLD validation" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/validators.rb
|
141
141
|
- lib/validators/constants.rb
|
142
142
|
- lib/validators/ip.rb
|
143
|
+
- lib/validators/tld.rb
|
143
144
|
- lib/validators/validates_cnpj_format_of.rb
|
144
145
|
- lib/validators/validates_cpf_format_of.rb
|
145
146
|
- lib/validators/validates_datetime.rb
|