Issue #3788 has been updated by Adam Majer.


The original argument is quite simple.

 1. URI RFC defines structure of URI (text) so it can be parsed by Ruby's URI (class) and other implementation. RFC define the interop.

 2. Purpose of URI Ruby class is to permit access to read, edit and use such URI transparently. URI class should deal with any encoding/unencoding issues.

 3. Not handling special escaping of the IPv6 literal internally in the URI Ruby class will result in spaghetti code and code duplication elsewhere. Marcus' example is exactly what happens not only inside Ruby codebase, but in other applications. The expectation is a hostname can be passed to other classes. For example,

  url = URI.parse( 'http://[::1]:8080/test/Test' )
  TCPSocket.new( url.host, url.port )

So where should this be fixed? In *every* piece of code that uses URI to connect or in URI helper class?

Here's another library (C++) that does this the way I expected it to,
    http://doc.trolltech.com/4.6/qurl.html#host

######
QUrl u( "http://[::1]:8080/test" );
u.host() => "::1"
######

In my opinion, adding dnssafehost to URI is bad design. Instead that should be the job the DNS class. "DNS Safe" has impact on protocol level, not API level.

My expectation was that URI.host should return unescaped hostname/IP and URI.host= should take unescaped as argument and escape them to produce a valid URI. This interface could then be easily extended to work with IRI (International domains).


maybe the solution is to rename current members host and host= to host_rfc3986 and host_rfc3986=. Similar syntax already exists in other classes like Time.


Alternatively, have URL.host return a new Host class (non-string) that deals with encoding/unencoding per URI RFC.


Of course, it is up to you to decide how you chose to design this. Again, RFC does not define what URL.host returns. Instead it defines host - a specific part of URL string.

----------------------------------------
http://redmine.ruby-lang.org/issues/show/3788

----------------------------------------
http://redmine.ruby-lang.org