From: John Joyce Date: 2007-08-30T01:54:45+09:00 Subject: Re: Bug in URI.parse? On Aug 29, 2007, at 9:33 AM, Andrew Beers wrote: > I have looked through the archives for the mailing list, but didn't > see > this issue addressed. So here goes. > > > > My local machine is named 3beers-wrk. I achieved this by putting an > entry in my local hosts file (since I'm on Windows, this would be in > \windows\system32\drivers\etc\hosts). However, I have also seen the > issue below reproduce with a machine whose name is similar, say > 12345-server. > > > > Below is a capture of my session with the shell, then with irb: > > > > H:\>ping 3beers-wrk > > > > Pinging 3beers-wrk [127.0.0.1] with 32 bytes of data: > > > > Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 > > Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 > > ... > > > > H:\>irb > > > > irb(main):001:0> require 'uri' > > => true > > > > irb(main):002:0> URI.parse("http://3beers-wrk.tsi.lan") > > => # > > > > irb(main):003:0> URI.parse("http://3beers-wrk") > > URI::InvalidURIError: the scheme http does not accept registry part: > 3beers-wrk (or bad hostname?) > > from > c:/p4/workgroup-1.0/workgroup-support/ruby/lib/ruby/1.8/uri/ > generic.rb:1 > 94:in `initialize' > > from > c:/p4/workgroup-1.0/workgroup-support/ruby/lib/ruby/1.8/uri/http.rb: > 46:i > n `initialize' > > from > c:/p4/workgroup-1.0/workgroup-support/ruby/lib/ruby/1.8/uri/ > common.rb:48 > 4:in `new' > > from > c:/p4/workgroup-1.0/workgroup-support/ruby/lib/ruby/1.8/uri/ > common.rb:48 > 4:in `parse' > > from (irb):3 > > from > c:/p4/workgroup-1.0/workgroup-support/ruby/lib/ruby/1.8/uri/http.rb:57 > > > > URI.parse() is not properly parsing the non-qualified name 3beers-wrk > (though it does properly parse a fully-qualified hostname), which > seems > to be in line with the grammar set forth in RFC2396. However, the RFC > makes the following comment: "In practice, however, the host > component > may be a local domain literal" (section 3.2). This suggests that the > above URI is entirely valid. Further, this URI is acceptable to Web > browsers. > > > > Is this a bug? How can I handle this seemingly valid URI? > > > > Thanks! > > Andrew > Good question! I've yet to figure out a good way to handle the InvalidURI errors myself. Makes URI.parse pretty useless unless you have a way to handle URI class's errors raised.