Project

General

Profile

Actions

Bug #12235

closed

URI.encode issue with square brackets

Added by lucaspiller (Luca Spiller) over 8 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[ruby-core:74737]

Description

URI::Encode doesn't correctly handle square brackets in the path of a URL:

> URI.encode('http://example.com/resource[1].doc')
=> "http://example.com/resource[1].doc"

It should return "http://example.com/resource%5B1%5D.doc".

As per RFC3986, square brackets are only valid in the host part, not the path part.

URI.parse correctly raises an error if a URL has square brackets in the path, which means URI::encode can return something that is rejected by URI.parse:

> URi.parse('http://example.com/resource[1].doc')
URI::InvalidURIError: bad URI(is not URI?): http://example.com/resource[1].doc

> URI.parse(URI::encode('http://example.com/resource[1].doc'))
URI::InvalidURIError: bad URI(is not URI?): http://example.com/resource[1].doc

Tested on Ruby 2.1.5 and 2.3.0 on OS X and Linux.


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #10619: URI::HTTP#query= behavior changed for 2396 urisClosednaruse (Yui NARUSE)Actions
Related to Ruby master - Bug #9806: URI#encode doesn't encode characters '[' and ']'. They should be encoded as %5B and %5D respectively.ClosedActions

Updated by lucaspiller (Luca Spiller) over 8 years ago

  • Subject changed from URI::Encode issue with square brackets to URI.encode issue with square brackets
Actions #3

Updated by naruse (Yui NARUSE) over 8 years ago

  • Related to Bug #10619: URI::HTTP#query= behavior changed for 2396 uris added
Actions #5

Updated by znz (Kazuhiro NISHIYAMA) over 7 years ago

  • Related to Bug #9806: URI#encode doesn't encode characters '[' and ']'. They should be encoded as %5B and %5D respectively. added

Updated by robb (Robb Shecter) over 3 years ago

I just ran into this. My app is generating URLs which it cannot then parse.

Actions #7

Updated by jeremyevans0 (Jeremy Evans) over 2 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0