From: Rob Biedenharn Date: 2009-08-28T01:07:36+09:00 Subject: Re: Found a ruby bug in the URI class, what do I do? On Aug 27, 2009, at 10:31 AM, Michael Fellinger wrote: > On Thu, Aug 27, 2009 at 4:00 PM, Victor Pereira > wrote: >> 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}") >> URI::InvalidURIError: bad URI(is not URI?): >> http://xpto.com/index.asp? >> action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247} >> 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. 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 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? action=showproduct&id={D3E21D33-6DFF-4355-9324-AE1395CEB247}" => "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=%7BD3E21D33-6DFF-4355-9324-AE1395CEB247%7D " irb> u1=URI.parse(URI.escape(u)) => # 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 >> >> Best regards, > > Just file a bug at 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 :) > >> >> VP > > -- > Michael Fellinger > CTO, The Rubyists, LLC > 972-996-5199 > Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com