Skip to content

Commit

Permalink
Merge branch 'fix-numeric-check' of https://github.com/lupine/validat…
Browse files Browse the repository at this point in the history
  • Loading branch information
KimNorgaard committed Dec 20, 2016
2 parents a2d823f + 2cda5d9 commit a331805
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions lib/validates_hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ def validate_each(record, attribute, value)
# CHECK 4: the unqualified hostname portion cannot consist of
# numeric values only
if options[:allow_numeric_hostname] == false and labels.length > 0
is_numeric_only = (
(
Integer(labels[0]) rescue false
) ? true : false
)
is_numeric_only = labels[0] =~ /\A\d+\z/
add_error(record, attribute, :hostname_label_is_numeric) if is_numeric_only
end

Expand Down Expand Up @@ -189,11 +185,7 @@ def validate_each(record, attribute, value)
# CHECK 1: if there is only one label it cannot be numeric even
# though numeric hostnames are allowed
if options[:allow_numeric_hostname] == true
is_numeric_only = (
(
Integer(labels[0]) rescue false
) ? true : false
)
is_numeric_only = labels[0] =~ /\A\d+\z/
if is_numeric_only and labels.size == 1
add_error(record, attribute, :single_numeric_hostname_label)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/validates_hostname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
:name_with_wildcard => '12345',
:name_with_valid_tld => '12345.org',
:name_with_test_tld => '12345.test',
:name_with_numeric_hostname => 'test',
:name_with_numeric_hostname => '0x12345',
:name_with_blank => '12345',
:name_with_nil => '12345'
record.save.should_not be_truthy
Expand Down

0 comments on commit a331805

Please sign in to comment.