0 Replies Latest reply on Aug 8, 2013 7:10 AM by Gerbrand Stap

    Let URI accept ppp_peer as hostname

    Gerbrand Stap

      URI (extension/uri) can be used in RhoElements by specifying [require 'uri'] and follows RFC 2396 when parsing uri's.

      When a Windows Mobile device is connected to a host computer using ActiveSync/Windows Mobile Device Center, it can reach this host computer using the hostname ppp_peer. But according to RFC 2396 a hostname can not contain an underscore (_), and the URI class follows this RFC strictly. So if you validate user input of an uri using the URI class, you have a problem.

      Fortunately URI also allows specifying additional regular expression patterns to parse custom uri's. Use the following code to specifically allow ppp_peer as hostname:

       

      # Supply regexp that also accepts 'ppp_peer' as a hostname.

      parser = URI::Parser.new( :HOSTNAME => "(?:ppp_peer)|(?:#{URI::REGEXP::PATTERN::HOSTNAME})" )

      parser.parse( "http://ppp_peer:80/test" )

       

      => #<URI::HTTP:0x297daa0 URL:http://ppp_peer/test>