lib/mongo/uri/srv_protocol.rb
# Validates the hostname used in an SRV URI.
#
# The hostname cannot include a port.
#
# The hostname must not begin with a dot, end with a dot, or have
# consecutive dots. The hostname must have a minimum of 3 total
# components (foo.bar.tld).
#
# Raises Error::InvalidURI if validation fails.
Validates the hostname used in an SRV URI.
The hostname cannot include a port.

The hostname must not begin with a dot, end with a dot, or have
consecutive dots. The hostname must have a minimum of 3 total
components (foo.bar.tld).

Raises Error::InvalidURI if validation fails.
Validates the hostname used in an SRV URI . The hostname cannot include a port . The hostname must not begin with a dot end with a dot or have consecutive dots . The hostname must have a minimum of 3 total components ( foo . bar . tld ) . Raises Error :: InvalidURI if validation fails .
def validate_srv_hostname(hostname)
        raise_invalid_error!(INVALID_PORT) if hostname.include?(HOST_PORT_DELIM)
        if hostname.start_with?('.')
          raise_invalid_error!("Hostname cannot start with a dot: #{hostname}")
        end
        if hostname.end_with?('.')
          raise_invalid_error!("Hostname cannot end with a dot: #{hostname}")
        end
        parts = hostname.split('.')
        if parts.any?(&:empty?)
          raise_invalid_error!("Hostname cannot have consecutive dots: #{hostname}")
        end
        if parts.length < 3
          raise_invalid_error!("Hostname must have a minimum of 3 components (foo.bar.tld): #{hostname}")
        end
      end
def validate_srv_hostname ( hostname ) raise_invalid_error! ( INVALID_PORT ) if hostname . include? ( HOST_PORT_DELIM ) if hostname . start_with? ( '.' ) raise_invalid_error! ( "Hostname cannot start with a dot: #{hostname}" ) end if hostname . end_with? ( '.' ) raise_invalid_error! ( "Hostname cannot end with a dot: #{hostname}" ) end parts = hostname . split ( '.' ) if parts . any? ( & :empty? ) raise_invalid_error! ( "Hostname cannot have consecutive dots: #{hostname}" ) end if parts . length < 3 raise_invalid_error! ( "Hostname must have a minimum of 3 components (foo.bar.tld): #{hostname}" ) end end
Validates the hostname used in an SRV URI.
Validates the hostname used in an SRV URI .
hostname