KimNorgaard / validates_hostname

Extension to ActiveRecord::Base for validating hostnames and domain names
MIT License
38 stars 12 forks source link

Possible bug in DomainnameValidator #13

Closed schwern closed 4 years ago

schwern commented 4 years ago

I noticed this block of code in DomainnameValidator.

        if value.is_a?(String)
          labels = value.split '.'
          labels.each do |label|
            # 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 = labels[0] =~ /\A\d+\z/
              if is_numeric_only and labels.size == 1
                add_error(record, attribute, :single_numeric_hostname_label)
              end
            end
          end
        end

label is never used. Is the loop unnecessary?

KimNorgaard commented 4 years ago

Yes, that looks like something I missed. I fixed it.