# Found a ruby bug in the URI class, what do I do?

**URL:** <https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494>\
**Category:** Ruby\
**Created:** [August 27, 2009, 3:59pm UTC](https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494 "2009-08-27T15:59:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![victorp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorp](https://www.ruby-forum.com/u/victorp)\
**Post date:** [August 27, 2009, 3:59pm UTC](https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494/1 "2009-08-27T15:59:57Z")

</div>

Hi,

i have to open an uri with open-uri but URI is raising me an error that  
an URL is an invalid uri:

> > p URI.split(“[http://xpto.com/index.asp?action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}](http://xpto.com/index.asp?action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D)”)  
> > URI::InvalidURIError: bad URI(is not URI?):  
> > [http://xpto.com/index.asp?action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}](http://xpto.com/index.asp?action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D)  
> > from  
> > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/uri/common.rb:436:in  
> > `split’  
> > from (irb):8  
> > from :0

That’s a strange ID but valid. I even checked the RFC 2396 and {} is not  
a reserved character.

Best regards,

VP

---

<div class="post-metadata">

**Author:** ![victorp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorp](https://www.ruby-forum.com/u/victorp)\
**Post date:** [August 27, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494/2 "2009-08-27T16:32:03Z")

</div>

On Thu, Aug 27, 2009 at 4:00 PM, Victor Pereira[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> `split’  
> Â from (irb):8  
> Â from :0
> 
> > >
> 
> That’s a strange ID but valid. I even checked the RFC 2396 and {} is not  
> a reserved character.
> 
> Best regards,

Just file a bug at [http://redmine.ruby-lang.org/](http://redmine.ruby-lang.org/) so it won’t be  
forgotten.  
If you also supply a patch against the uri lib, you get bonus points 🙂

---

<div class="post-metadata">

**Author:** ![victorp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorp](https://www.ruby-forum.com/u/victorp)\
**Post date:** [August 27, 2009, 6:08pm UTC](https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494/3 "2009-08-27T18:08:04Z")

</div>

On Aug 27, 2009, at 10:31 AM, Michael F. wrote:

> > URI::InvalidURIError: bad URI(is not URI?):  
> > That’s a strange ID but valid. I even checked the RFC 2396 and {}  
> > is not  
> > a reserved character.

But it is part of the ‘unwise’ set defined by RFC 2396 in:  
“2.4.3. Excluded US-ASCII Characters  
Although they are disallowed within the URI syntax, we include  
here a description of those US-ASCII characters that have been  
excluded and the reasons for their exclusion.”  
[http://www.faqs.org/rfcs/rfc2396.html](http://www.faqs.org/rfcs/rfc2396.html)

Just because a URI works in any (or even all) browser(s) doesn’t mean  
that it conforms to the standard for URIs.

I think that URI.split is doing the right thing.

URI.escape() might be a workaround for you:

irb\> u=“[http://xpto.com/index.asp](http://xpto.com/index.asp)?  
action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}”  
=\> “[http://xpto.com/index.asp](http://xpto.com/index.asp)?  
action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}”  
irb\> URI.escape(u)  
=\>  
"[http://xpto.com/index.asp?action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}](http://xpto.com/index.asp?action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D)  
"  
irb\> u1=URI.parse(URI.escape(u))  
=\> #\<URI::HTTP:0x38cbd8  
URL:[http://xpto.com/index.asp?action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}](http://xpto.com/index.asp?action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D)

> 

irb\> u1.query  
=\> “action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D”  
irb\> URI.unescape(u1.query)  
=\> “action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}”

-Rob

> –  
> Michael F.  
> CTO, The Rubyists, LLC  
> 972-996-5199

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![victorp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorp](https://www.ruby-forum.com/u/victorp)\
**Post date:** [August 28, 2009, 5:40pm UTC](https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494/4 "2009-08-28T17:40:10Z")

</div>

Rob,

to be in the ‘unwise’ doesn’t mean  
that it not conforms to the standard for URIs.

I’m escaping and it works, but in my option it could be handled by the  
lib.

VP

Rob B. wrote:

> On Aug 27, 2009, at 10:31 AM, Michael F. wrote:
> 
> > > URI::InvalidURIError: bad URI(is not URI?):  
> > > That’s a strange ID but valid. I even checked the RFC 2396 and {}  
> > > is not  
> > > a reserved character.
> 
> But it is part of the ‘unwise’ set defined by RFC 2396 in:  
> “2.4.3. Excluded US-ASCII Characters  
> Although they are disallowed within the URI syntax, we include  
> here a description of those US-ASCII characters that have been  
> excluded and the reasons for their exclusion.”  
> [RFC 2396 - Uniform Resource Identifiers (URI): Generic Syntax (RFC2396)](http://www.faqs.org/rfcs/rfc2396.html)
> 
> Just because a URI works in any (or even all) browser(s) doesn’t mean  
> that it conforms to the standard for URIs.
> 
> I think that URI.split is doing the right thing.
> 
> URI.escape() might be a workaround for you:
> 
> irb\> u=“[http://xpto.com/index.asp](http://xpto.com/index.asp)?  
> action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}”  
> =\> “[http://xpto.com/index.asp](http://xpto.com/index.asp)?  
> action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}”  
> irb\> URI.escape(u)  
> =\>  
> "[http://xpto.com/index.asp?action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}](http://xpto.com/index.asp?action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D)  
> "  
> irb\> u1=URI.parse(URI.escape(u))  
> =\> #\<URI::HTTP:0x38cbd8  
> URL:[http://xpto.com/index.asp?action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}](http://xpto.com/index.asp?action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D)
> 
> > 
> 
> irb\> u1.query  
> =\> “action=showproduct&id=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D”  
> irb\> URI.unescape(u1.query)  
> =\> “action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}”
> 
> -Rob
> 
> > –  
> > Michael F.  
> > CTO, The Rubyists, LLC  
> > 972-996-5199
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![victorp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/9fc29f/32.png) [@victorp](https://www.ruby-forum.com/u/victorp)\
**Post date:** [August 28, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/found-a-ruby-bug-in-the-uri-class-what-do-i-do/174494/5 "2009-08-28T18:12:50Z")

</div>

Sorry, Victor, but yes it does.

Quoting from the end of RFC 2396 section 2.4.3:

> [@](#):
>
> Other characters are excluded because gateways and other transport  
> agents are known to sometimes modify such characters, or they are used  
> as delimiters.  
> unwise = “{” | “}” | “|” | "" | “^” | “[” | “]” | “`”  
> Data corresponding to excluded characters must be escaped in order to  
> be properly represented within a URI.

So that last sentence pretty much nails it. Curly braces “…must be  
escaped in order to be properly represented within a URI.”

So you’ll have to continue to escape them yourself. It wouldn’t be  
right for the URI class to depart from the standard here.

-Rob

On Aug 28, 2009, at 11:40 AM, Victor Pereira wrote:

> Rob B. wrote:
> 
> > here a description of those US-ASCII characters that have been  
> > irb\> u="[http://xpto.com/index.asp](http://xpto.com/index.asp)?
> > 
> > > Michael F.  
> > > CTO, The Rubyists, LLC  
> > > 972-996-5199
> > 
> > Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> > removed\_email\_address@domain.invalid
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid  
+1 513-295-4739  
Skype: rob.biedenharn
