Feature #1013

Handling of [ and ] in URIs

Added by tobias (Tobias Gruetzmacher) over 3 years ago. Updated about 1 year ago.

[ruby-core:21351]
Status:Rejected Start date:01/15/2009
Priority:Normal Due date:
Assignee:akira (akira yamada) % Done:

0%

Category:-
Target version:-

Description

This is a little bit related to the old Tracker entry http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=1952

The problem surfaced for me again just today, while working with WWW::Mechanize parsing a private website (sorry, no public test case) using some Drupal image gallery software. It produces URIs like http://localhost/images/file[1].jpg without escaping the [ and ].

I know this is against the RFC (RFC 3986 states in section 3.2.2. Host: "This is the only place where square bracket characters are allowed in the URI syntax."), but I would be glad if Ruby was a little bit more liberal (in the old spirit of "Be liberal with what you accept and strict with what you produce") and accept these malformed URIs. Bonus points if it also corrected them...

I had posted a "fix" to the old tracker item, but while it is a working workaround, it doesn't look like a valid solution to me anymore.

This bug also applies to Ruby 1.9.

History

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Assignee set to akira (akira yamada)

Updated by akira (akira yamada) over 3 years ago

  • Status changed from Open to Rejected
[Ruby 1.8]
"[" and "]" can not be in URI::PATTERN::UNRESERVED because the URI module is used as a syntax checker of URI like strings.

[Ruby 1.9]
It is basically same as above.  But you can use your URI parser.  Example: 

>> require "uri"
=> true
>> parser = URI::Parser.new(:UNRESERVED=>URI::PATTERN::UNRESERVED+'\[\]')
=> #<URI::Parser:0xa09f9d4>
>> uri = parser.parse("http://exmaple.jp/[1].jpg")
=> #<URI::HTTP:0xa0870c8 URL:http://exmaple.jp/[1].jpg>
>> uri.path
=> "/[1].jpg"
>> URI.parse("http://exmaple.jp/[1].jpg")
URI::InvalidURIError: bad URI(is not URI?): http://exmaple.jp/[1].jpg

Also available in: Atom PDF