validates_hostname 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +0 -0
- data/MIT-LICENSE +0 -0
- data/Rakefile +0 -0
- data/lib/validates_hostname.rb +102 -44
- data/lib/validates_hostname/version.rb +1 -1
- data/validates_hostname.gemspec +8 -5
- metadata +44 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95afd4c7854435996ba31b490d2fe4472460c6e0
|
4
|
+
data.tar.gz: a3ab78cc20012156408c984225c274556772f8c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01762b519ad24527b5a39f9a956693dd7b3f4e45ddec56323ec10349e2d34601d7c8031a612d9812b8ae22938d28cf37ea8cc3bec64f71bef178a70f449608e0
|
7
|
+
data.tar.gz: 94d45c227dede08a555069d661644252b2553c48559d52ff25331332b64537183348fe699ee9202522150e2be10fd38b66be96a4a79f9737c0b4ccec215f2f50
|
data/CHANGELOG.rdoc
CHANGED
File without changes
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/validates_hostname.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/concern'
|
2
|
+
require 'active_record'
|
2
3
|
require 'active_model'
|
3
4
|
|
4
5
|
module PAK
|
@@ -6,45 +7,86 @@ module PAK
|
|
6
7
|
autoload :VERSION, 'validates_hostname/version'
|
7
8
|
|
8
9
|
# List from IANA: http://www.iana.org/domains/root/db/
|
10
|
+
# http://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
9
11
|
ALLOWED_TLDS = %w(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
12
|
+
. abogado ac academy accountants active actor ad adult ae aero af ag agency ai
|
13
|
+
airforce al allfinanz alsace am amsterdam an android ao aq aquarelle ar archi
|
14
|
+
army arpa as asia associates at attorney au auction audio autos aw ax axa az ba
|
15
|
+
band bank bar bargains bayern bb bd be beer berlin best bf bg bh bi bid bike
|
16
|
+
bio biz bj black blackfriday bloomberg blue bm bmw bn bnpparibas bo boo
|
17
|
+
boutique br brussels bs bt budapest build builders business buzz bv bw by bz
|
18
|
+
bzh ca cab cal camera camp cancerresearch capetown capital caravan cards care
|
19
|
+
career careers cartier casa cash cat catering cc cd center ceo cern cf cg ch
|
20
|
+
channel cheap christmas chrome church ci citic city ck cl claims cleaning click
|
21
|
+
clinic clothing club cm cn co coach codes coffee college cologne com community
|
22
|
+
company computer condos construction consulting contractors cooking cool coop
|
23
|
+
country cr credit creditcard cricket crs cruises cu cuisinella cv cw cx cy
|
24
|
+
cymru cz dad dance dating day de deals degree delivery democrat dental dentist
|
25
|
+
desi dev diamonds diet digital direct directory discount dj dk dm dnp do docs
|
26
|
+
domains doosan durban dvag dz eat ec edu education ee eg email emerck energy
|
27
|
+
engineer engineering enterprises equipment er es esq estate et eu eurovision
|
28
|
+
eus events everbank exchange expert exposed fail farm fashion feedback fi
|
29
|
+
finance financial firmdale fish fishing fit fitness fj fk flights florist
|
30
|
+
flowers flsmidth fly fm fo foo forsale foundation fr frl frogans fund furniture
|
31
|
+
futbol ga gal gallery garden gb gbiz gd ge gent gf gg ggee gh gi gift gifts
|
32
|
+
gives gl glass gle global globo gm gmail gmo gmx gn google gop gov gp gq gr
|
33
|
+
graphics gratis green gripe gs gt gu guide guitars guru gw gy hamburg haus
|
34
|
+
healthcare help here hiphop hiv hk hm hn holdings holiday homes horse host
|
35
|
+
hosting house how hr ht hu ibm id ie il im immo immobilien in industries info
|
36
|
+
ing ink institute insure int international investments io iq ir irish is it iwc
|
37
|
+
je jetzt jm jo jobs joburg jp juegos kaufen kddi ke kg kh ki kim kitchen kiwi
|
38
|
+
km kn koeln kp kr krd kred kw ky kz la lacaixa land lat latrobe lawyer lb lc
|
39
|
+
lds lease legal lgbt li lidl life lighting limited limo link lk loans london
|
40
|
+
lotto lr ls lt ltda lu luxe luxury lv ly ma madrid maison management mango
|
41
|
+
market marketing mc md me media meet melbourne meme memorial menu mg mh miami
|
42
|
+
mil mini mk ml mm mn mo mobi moda moe monash money mormon mortgage moscow
|
43
|
+
motorcycles mov mp mq mr ms mt mu museum mv mw mx my mz na nagoya name navy nc
|
44
|
+
ne net network neustar new nexus nf ng ngo nhk ni ninja nl no np nr nra nrw nu
|
45
|
+
nyc nz okinawa om ong onl ooo org organic osaka otsuka ovh pa paris partners
|
46
|
+
parts party pe pf pg ph pharmacy photo photography photos physio pics pictures
|
47
|
+
pink pizza pk pl place plumbing pm pn pohl poker porn post pr praxi press pro
|
48
|
+
prod productions prof properties property ps pt pub pw py qa qpon quebec re
|
49
|
+
realtor recipes red rehab reise reisen reit ren rentals repair report
|
50
|
+
republican rest restaurant reviews rich rio rip ro rocks rodeo rs rsvp ru ruhr
|
51
|
+
rw ryukyu sa saarland sale samsung sarl sb sc sca scb schmidt schule schwarz
|
52
|
+
science scot sd se services sew sexy sg sh shiksha shoes shriram si singles sj
|
53
|
+
sk sky sl sm sn so social software sohu solar solutions soy space spiegel sr st
|
54
|
+
su supplies supply support surf surgery suzuki sv sx sy sydney systems sz
|
55
|
+
taipei tatar tattoo tax tc td technology tel tf tg th tienda tips tires tirol
|
56
|
+
tj tk tl tm tn to today tokyo tools top town toys tp tr trade training travel
|
57
|
+
trust tt tui tv tw tz ua ug uk university uno uol us uy uz va vacations vc ve
|
58
|
+
vegas ventures versicherung vet vg vi viajes video villas vision vlaanderen vn
|
59
|
+
vodka vote voting voto voyage vu wales wang watch webcam website wed wedding wf
|
60
|
+
whoswho wien wiki williamhill wme work works world ws wtc wtf xn--1qqw23a
|
61
|
+
xn--3bst00m xn--3ds443g xn--3e0b707e xn--45brj9c xn--45q11c xn--4gbrim
|
62
|
+
xn--55qw42g xn--55qx5d xn--6frz82g xn--6qq986b3xl xn--80adxhks xn--80ao21a
|
63
|
+
xn--80asehdb xn--80aswg xn--90a3ac xn--c1avg xn--cg4bki xn--clchc0ea0b2g2a9gcd
|
64
|
+
xn--czr694b xn--czrs0t xn--czru2d xn--d1acj3b xn--d1alf xn--fiq228c5hs
|
65
|
+
xn--fiq64b xn--fiqs8s xn--fiqz9s xn--flw351e xn--fpcrj9c3d xn--fzc2c9e2c
|
66
|
+
xn--gecrj9c xn--h2brj9c xn--hxt814e xn--i1b6b1a6a2e xn--io0a7i xn--j1amh
|
67
|
+
xn--j6w193g xn--kprw13d xn--kpry57d xn--kput3i xn--l1acc xn--lgbbat1ad8j
|
68
|
+
xn--mgb9awbf xn--mgba3a4f16a xn--mgbaam7a8h xn--mgbab2bd xn--mgbayh7gpa
|
69
|
+
xn--mgbbh1a71e xn--mgbc0a9azcg xn--mgberp4a5d4ar xn--mgbx4cd0ab xn--ngbc5azd
|
70
|
+
xn--node xn--nqv7f xn--nqv7fs00ema xn--o3cw4h xn--ogbpf8fl xn--p1acf xn--p1ai
|
71
|
+
xn--pgbs0dh xn--q9jyb4c xn--qcka1pmc xn--rhqv96g xn--s9brj9c xn--ses554g
|
72
|
+
xn--unup4y xn--vermgensberater-ctb xn--vermgensberatung-pwb xn--vhquv
|
73
|
+
xn--wgbh1c xn--wgbl6a xn--xhq521b xn--xkc2al3hye2a xn--xkc2dl3a5ee0h
|
74
|
+
xn--yfro4i67o xn--ygbi2ammx xn--zfr164b xxx xyz yachts yandex ye yoga yokohama
|
75
|
+
youtube yt za zip zm zone zuerich zw
|
36
76
|
)
|
37
|
-
|
77
|
+
|
38
78
|
DEFAULT_ERROR_MSG = {
|
39
|
-
:invalid_hostname_length => '
|
40
|
-
:invalid_label_length => '
|
41
|
-
:label_begins_or_ends_with_hyphen => '
|
42
|
-
:label_contains_invalid_characters => "
|
79
|
+
:invalid_hostname_length => 'must be between 1 and 255 characters long',
|
80
|
+
:invalid_label_length => 'must be between 1 and 63 characters long',
|
81
|
+
:label_begins_or_ends_with_hyphen => 'begins or ends with hyphen',
|
82
|
+
:label_contains_invalid_characters => "contains invalid characters (valid characters: [%{valid_chars}])",
|
43
83
|
:hostname_label_is_numeric => 'unqualified hostname part cannot consist of numeric values only',
|
44
|
-
:hostname_is_not_fqdn => '
|
45
|
-
:single_numeric_hostname_label => '
|
84
|
+
:hostname_is_not_fqdn => 'is not a fully qualified domain name',
|
85
|
+
:single_numeric_hostname_label => 'cannot consist of a single numeric label',
|
86
|
+
:hostname_contains_consecutive_dots => 'must not contain consecutive dots',
|
87
|
+
:hostname_ends_with_dot => 'must not end with a dot'
|
46
88
|
}.freeze
|
47
|
-
|
89
|
+
|
48
90
|
class HostnameValidator < ActiveModel::EachValidator
|
49
91
|
def initialize(options)
|
50
92
|
opts = {
|
@@ -52,16 +94,18 @@ module PAK
|
|
52
94
|
:require_valid_tld => false,
|
53
95
|
:valid_tlds => ALLOWED_TLDS,
|
54
96
|
:allow_numeric_hostname => false,
|
55
|
-
:allow_wildcard_hostname => false
|
97
|
+
:allow_wildcard_hostname => false,
|
98
|
+
:allow_root_label => false
|
56
99
|
}.merge(options)
|
57
100
|
super(opts)
|
58
101
|
end
|
59
|
-
|
102
|
+
|
60
103
|
def validate_each(record, attribute, value)
|
61
104
|
value ||= ''
|
105
|
+
|
62
106
|
# maximum hostname length: 255 characters
|
63
107
|
add_error(record, attribute, :invalid_hostname_length) unless value.length.between?(1, 255)
|
64
|
-
|
108
|
+
|
65
109
|
# split each hostname into labels and do various checks
|
66
110
|
if value.is_a?(String)
|
67
111
|
labels = value.split '.'
|
@@ -84,7 +128,7 @@ module PAK
|
|
84
128
|
|
85
129
|
# CHECK 4: the unqualified hostname portion cannot consist of
|
86
130
|
# numeric values only
|
87
|
-
if options[:allow_numeric_hostname] == false
|
131
|
+
if options[:allow_numeric_hostname] == false and labels.length > 0
|
88
132
|
is_numeric_only = (
|
89
133
|
(
|
90
134
|
Integer(labels[0]) rescue false
|
@@ -96,14 +140,28 @@ module PAK
|
|
96
140
|
# CHECK 5: in order to be fully qualified, the full hostname's
|
97
141
|
# TLD must be valid
|
98
142
|
if options[:require_valid_tld] == true
|
143
|
+
my_tld = value == '.' ? value : labels.last
|
144
|
+
my_tld ||= ''
|
99
145
|
has_tld = options[:valid_tlds].select {
|
100
|
-
|tld| tld =~ /^#{Regexp.escape(
|
146
|
+
|tld| tld =~ /^#{Regexp.escape(my_tld)}$/i
|
101
147
|
}.empty? ? false : true
|
102
148
|
add_error(record, attribute, :hostname_is_not_fqdn) unless has_tld
|
103
149
|
end
|
150
|
+
|
151
|
+
# CHECK 6: hostname may not contain consecutive dots
|
152
|
+
if value =~ /\.\./
|
153
|
+
add_error(record, attribute, :hostname_contains_consecutive_dots)
|
154
|
+
end
|
155
|
+
|
156
|
+
# CHECK 7: do not allow trailing dot unless option is set
|
157
|
+
if options[:allow_root_label] == false
|
158
|
+
if value =~ /\.$/
|
159
|
+
add_error(record, attribute, :hostname_ends_with_dot)
|
160
|
+
end
|
161
|
+
end
|
104
162
|
end
|
105
163
|
end
|
106
|
-
|
164
|
+
|
107
165
|
def add_error(record, attr_name, message, *interpolators)
|
108
166
|
args = {
|
109
167
|
:default => [DEFAULT_ERROR_MSG[message], options[:message]],
|
@@ -121,10 +179,10 @@ module PAK
|
|
121
179
|
}.merge(options)
|
122
180
|
super(opts)
|
123
181
|
end
|
124
|
-
|
182
|
+
|
125
183
|
def validate_each(record, attribute, value)
|
126
184
|
super
|
127
|
-
|
185
|
+
|
128
186
|
if value.is_a?(String)
|
129
187
|
labels = value.split '.'
|
130
188
|
labels.each do |label|
|
@@ -143,7 +201,7 @@ module PAK
|
|
143
201
|
end
|
144
202
|
end
|
145
203
|
end
|
146
|
-
|
204
|
+
|
147
205
|
def add_error(record, attr_name, message, *interpolators)
|
148
206
|
args = {
|
149
207
|
:default => [DEFAULT_ERROR_MSG[message], options[:message]],
|
@@ -173,4 +231,4 @@ module PAK
|
|
173
231
|
end
|
174
232
|
end
|
175
233
|
|
176
|
-
ActiveRecord::Base.send(:include, PAK::ValidatesHostname)
|
234
|
+
ActiveRecord::Base.send(:include, PAK::ValidatesHostname)
|
data/validates_hostname.gemspec
CHANGED
@@ -16,9 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.licenses = 'MIT'
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_runtime_dependency '
|
20
|
-
s.add_runtime_dependency '
|
21
|
-
|
22
|
-
s.
|
23
|
-
s.
|
19
|
+
s.add_runtime_dependency 'activerecord', '>= 3.0'
|
20
|
+
s.add_runtime_dependency 'activesupport', '>= 3.0'
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.14'
|
23
|
+
s.add_development_dependency 'rspec-rails'
|
24
|
+
s.add_development_dependency 'rails-all'
|
25
|
+
s.add_development_dependency 'sqlite3'
|
26
|
+
s.add_development_dependency 'pry-debugger'
|
24
27
|
end
|
metadata
CHANGED
@@ -1,37 +1,65 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_hostname
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kim Nørgaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - '>='
|
32
60
|
- !ruby/object:Gem::Version
|
33
61
|
version: '0'
|
34
|
-
type: :
|
62
|
+
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
@@ -39,13 +67,13 @@ dependencies:
|
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
70
|
+
name: rails-all
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - '>='
|
46
74
|
- !ruby/object:Gem::Version
|
47
75
|
version: '0'
|
48
|
-
type: :
|
76
|
+
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
@@ -53,13 +81,13 @@ dependencies:
|
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
84
|
+
name: sqlite3
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - '>='
|
60
88
|
- !ruby/object:Gem::Version
|
61
89
|
version: '0'
|
62
|
-
type: :
|
90
|
+
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
@@ -67,13 +95,13 @@ dependencies:
|
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: pry-debugger
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - '>='
|
74
102
|
- !ruby/object:Gem::Version
|
75
103
|
version: '0'
|
76
|
-
type: :
|
104
|
+
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
@@ -89,13 +117,13 @@ extra_rdoc_files:
|
|
89
117
|
- CHANGELOG.rdoc
|
90
118
|
- MIT-LICENSE
|
91
119
|
files:
|
92
|
-
- validates_hostname.gemspec
|
93
|
-
- MIT-LICENSE
|
94
120
|
- CHANGELOG.rdoc
|
121
|
+
- MIT-LICENSE
|
95
122
|
- README.rdoc
|
96
123
|
- Rakefile
|
97
|
-
- lib/validates_hostname/version.rb
|
98
124
|
- lib/validates_hostname.rb
|
125
|
+
- lib/validates_hostname/version.rb
|
126
|
+
- validates_hostname.gemspec
|
99
127
|
homepage: https://github.com/KimNorgaard/validates_hostname
|
100
128
|
licenses:
|
101
129
|
- MIT
|
@@ -116,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
144
|
version: '0'
|
117
145
|
requirements: []
|
118
146
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.2.2
|
120
148
|
signing_key:
|
121
149
|
specification_version: 4
|
122
150
|
summary: Checks for valid hostnames
|