Project

General

Profile

Feature #1013

Handling of [ and ] in URIs

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

Status:
Rejected
Priority:
Normal
Target version:
-
[ruby-core:21351]

Description

=begin
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.
=end

History

#1

Updated by ko1 (Koichi Sasada) over 10 years ago

  • Assignee set to akira (akira yamada)

=begin

=end

#2

Updated by akira (akira yamada) over 10 years ago

  • Status changed from Open to Rejected

=begin
[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.path
=> "/[1].jpg"
URI.parse("http://exmaple.jp/[1].jpg")
URI::InvalidURIError: bad URI(is not URI?): http://exmaple.jp/[1].jpg

=end

Also available in: Atom PDF