I’m pretty sure this is a bug, and it seem so obvious that I’m thinking
I might be doing something wrong. Check it out:
require “uri”
=> true
URI.parse(“http://whatever.domain.com”)
=> #<URI::HTTP:0x2b2b7c URL:http://whatever.domain.com>
URI.parse(“http://whatever_again.domain.com”)
URI::InvalidURIError: the scheme http does not accept registry part:
whatever_again.domain.com (or bad hostname?)
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/uri/generic.rb:195:in
initialize' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/uri/http.rb:78:in
initialize’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/uri/common.rb:488:in
new' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/uri/common.rb:488:in
parse’
from (irb):45
When you add an underscore the sub domain it raises an exception, even
though that is a perfectly valid host name. I dug deeper and found the
following:
URI.split(“http://whatever.domain.com”)
=> [“http”, nil, “whatever.domain.com”, nil, nil, “”, nil, nil, nil]
URI.split(“http://whatever_again.domain.com”)
=> [“http”, nil, nil, nil, “whatever_again.domain.com”, “”, nil, nil,
nil]
Notice its not recognizing the second URI as a host, which is really
strange, its actually saying its the registry.
Anyways, can anyone shed some light on this or do you have any ideas how
I can easily patch this?
Check out the split method source:
http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI.html#M009379
That doesn’t look to easy to patch since its one big regular expression
that breaks up the string.
Thanks for your help!