Bugs: Browse | Submit New | Admin

[#13504] URI.parse() won't properly parse some non-qualified hostnames

Date:
2007-08-29 22:07
Priority:
3
Submitted By:
Andrew Beers (rubybud)
Assigned To:
Shyouhei Urabe (shyouhei)
Category:
Misc / Other Standard Library
State:
Open
Platform:
 
Summary:
URI.parse() won't properly parse some non-qualified hostnames

Detailed description
URI.parse() will not parse a URI containing a non-qualified hostname that begins with a number.  An IRB session:

irb(main):001:0> require 'uri'
=> true

irb(main):002:0> URI.parse("http://threebee")
=> #<URI::HTTP:0x161319e URL:http://threebee>

irb(main):003:0> URI.parse("http://3bee")
URI::InvalidURIError: the scheme http does not accept registry part: 3bee (or bad hostname?)
        from c:/p4/tableau-3-5/workgroup-support/ruby/lib/ruby/1.8/uri/generic.rb:194:in `initialize'
        from c:/p4/tableau-3-5/workgroup-support/ruby/lib/ruby/1.8/uri/http.rb:46:in `initialize'
        from c:/p4/tableau-3-5/workgroup-support/ruby/lib/ruby/1.8/uri/common.rb:484:in `new'
        from c:/p4/tableau-3-5/workgroup-support/ruby/lib/ruby/1.8/uri/common.rb:484:in `parse'
        from (irb):3
        from ♥:0

irb(main):004:0> URI.parse("http://3bee.foo.com")
=> #<URI::HTTP:0x16108fe URL:http://3bee.foo.com>

Note that the qualified form parses correctly, suggesting that the hostname is acceptable.

A discussion of this case can be found in ruby-talk, archived here:

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/266700?266598-266714

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-01-18 19:12
Sender: Andrew Beers

Note that the following will also fail with an InvalidURIError:

URI.parse("http://xp_workstation:80/foo/bar.js")

I'll alter my patch...
Date: 2007-10-08 16:41
Sender: Andrew Beers

Patch is now attached.
Date: 2007-10-04 17:53
Sender: Andrew Beers

Based on the discussion archived above (also at
http://www.nabble.com/Bug-in-URI.parse--tf4348168.html#a12388384
since the above isn't working today), I am attaching a patch
for two files:

uri/common.rb
and 
test_common.rb

Date: 2007-09-06 18:51
Sender: Andrew Beers

Note that the URI also will not parse when the bare hostname
is a valid local hostname.

Attached Files:

Name Description Download
ruby-patch.zip Download

Changes:

Field Old Value Date By
File Added2639: ruby-patch.zip2007-10-08 16:41rubybud