domain_name_validator 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md CHANGED
@@ -9,6 +9,13 @@
9
9
  circumstances. This validation would, for example, reject a domain name
10
10
  such as "test.domain".
11
11
 
12
+ * (0.4.1) Added "info" as a valid extra-long TLD. How i missed this one, I
13
+ have no idea.
14
+
15
+ * (0.4.2) Added a check for zero-length domain names, either empty strings
16
+ or Ruby nil values being passed in. In practice, these edge cases were
17
+ actually happening.
18
+
12
19
  0.3 (2013-06-28)
13
20
  ----------------
14
21
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- domain_name_validator (0.4)
4
+ domain_name_validator (0.4.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -13,7 +13,7 @@ class DomainNameValidator
13
13
 
14
14
  ERRS = {
15
15
  :bogus_tld =>
16
- 'Malformed TLD',
16
+ 'Malformed TLD: Could not possibly match any valid TLD',
17
17
  :illegal_chars =>
18
18
  'Domain label contains an illegal character',
19
19
  :illegal_start =>
@@ -31,7 +31,9 @@ class DomainNameValidator
31
31
  :min_level_size =>
32
32
  'Minimum domain level limit of 2 not achieved',
33
33
  :top_numerical =>
34
- 'The top-level domain (TLD) cannot be numerical'
34
+ 'The top-level domain (TLD) cannot be numerical',
35
+ :zero_size =>
36
+ 'Zero-length domain name'
35
37
  }
36
38
 
37
39
  # Validates the proper formatting of a normalized domain name, i.e. - a
@@ -48,27 +50,31 @@ class DomainNameValidator
48
50
  # 6. A domain name cannot begin with a period.
49
51
 
50
52
  def validate(dn, errs = [])
51
- errs << ERRS[:max_domain_size] if dn.size > MAX_DOMAIN_LENGTH
52
- parts = dn.split('.')
53
- errs << ERRS[:max_level_size] if parts.size > MAX_LEVELS
54
- errs << ERRS[:min_level_size] if parts.size < MIN_LEVELS
55
- parts.each do |p|
56
- errs << ERRS[:max_label_size] if p.size > MAX_LABEL_LENGTH
57
- errs << ERRS[:label_dash_begin] if p[0] == '-'
58
- errs << ERRS[:label_dash_end] if p[-1] == '-'
59
- errs << ERRS[:illegal_chars] unless p.match(/^[a-z0-9\-\_]+$/)
60
- end
61
- errs << ERRS[:top_numerical] if parts.last.match(/^[0-9]+$/)
62
- if parts.last.size < MIN_TLD_LENGTH || parts.last.size > MAX_TLD_LENGTH
63
- unless parts.last == 'arpa' ||
64
- parts.last == 'aero' ||
65
- parts.last == 'info' ||
66
- parts.last == 'museum' ||
67
- parts.last.match(/^xn--/)
68
- errs << ERRS[:bogus_tld]
53
+ errs << ERRS[:zero_size] if dn.nil? || dn.size == 0
54
+
55
+ if errs.size == 0
56
+ errs << ERRS[:max_domain_size] if dn.size > MAX_DOMAIN_LENGTH
57
+ parts = dn.split('.')
58
+ errs << ERRS[:max_level_size] if parts.size > MAX_LEVELS
59
+ errs << ERRS[:min_level_size] if parts.size < MIN_LEVELS
60
+ parts.each do |p|
61
+ errs << ERRS[:max_label_size] if p.size > MAX_LABEL_LENGTH
62
+ errs << ERRS[:label_dash_begin] if p[0] == '-'
63
+ errs << ERRS[:label_dash_end] if p[-1] == '-'
64
+ errs << ERRS[:illegal_chars] unless p.match(/^[a-z0-9\-\_]+$/)
65
+ end
66
+ errs << ERRS[:top_numerical] if parts.last.match(/^[0-9]+$/)
67
+ if parts.last.size < MIN_TLD_LENGTH || parts.last.size > MAX_TLD_LENGTH
68
+ unless parts.last == 'arpa' ||
69
+ parts.last == 'aero' ||
70
+ parts.last == 'info' ||
71
+ parts.last == 'museum' ||
72
+ parts.last.match(/^xn--/)
73
+ errs << ERRS[:bogus_tld]
74
+ end
69
75
  end
76
+ errs << ERRS[:illegal_start] if parts.first[0] == '.'
70
77
  end
71
- errs << ERRS[:illegal_start] if parts.first[0] == '.'
72
78
 
73
79
  errs.size == 0 # TRUE if valid, FALSE otherwise
74
80
  end
@@ -1,3 +1,3 @@
1
1
  class DomainNameValidator
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -13,6 +13,16 @@ describe DomainNameValidator do
13
13
  response.should be == true
14
14
  end
15
15
 
16
+ it 'should fail when it finds nil instead of a domain name' do
17
+ response = @validator.validate(nil)
18
+ response.should be == false
19
+ end
20
+
21
+ it 'should fail when it finds an empty string instead of a domain name' do
22
+ response = @validator.validate("")
23
+ response.should be == false
24
+ end
25
+
16
26
  it 'should fail when it finds a numeric top-level extension' do
17
27
  response = @validator.validate('keenertech.123')
18
28
  response.should be == false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_name_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &27415812 !ruby/object:Gem::Requirement
16
+ requirement: &28235004 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *27415812
24
+ version_requirements: *28235004
25
25
  description: Checks the validity of domain names.
26
26
  email:
27
27
  - dkeener@keenertech.com