Feature #1013

Handling of [ and ] in URIs

Added by tobias (Tobias Gruetzmacher) about 11 years ago. Updated over 8 years ago.

Target version:


This is a little bit related to the old Tracker entry

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.



Updated by ko1 (Koichi Sasada) almost 11 years ago

  • Assignee set to akira (akira yamada)




Updated by akira (akira yamada) almost 11 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
=> #URI::Parser:0xa09f9d4
uri = parser.parse("[1].jpg")
=> #
=> "/[1].jpg"
URI::InvalidURIError: bad URI(is not URI?):[1].jpg


Also available in: Atom PDF