title: Parsing URIs that have curly braces, URI::InvalidURIError: bad URI(is not URI?)
body: <p>Using ruby 1.9.2-p290. I came across an issue trying to parse a URI like the following:</p>
  
  <pre><code>require 'uri'
  my_uri = "http://www.anyserver.com/getdata?anyparameter={330C-B5A2}"
  the_uri = URI.parse(my_uri)
  </code></pre>
  
  <p>issuing the following error:</p>
  
  <pre><code>URI::InvalidURIError: bad URI(is not URI?)
  </code></pre>
  
  <p>I require a different solution than encoding the curly braces every time like this:</p>
  
  <pre><code>new_uri = URI.encode("http://www.anyserver.com/getdata?anyparameter={330C-B5A2}")
  =&gt; "http://www.anyserver.com/getdata?anyparameter=%7B330C-B5A2%7D"
  </code></pre>
  
  <p>Now I can parse the new_uri as usual, but had to do this every time I needed it. What is the simplest way to achieve this without doing it every time?</p>
  
  <p>I post my own solution as I hadn't seen this exactly as I solved it.</p>
  
  <hr>
  
  <pre><code># Accepts URIs when they contain curly braces
  # This overrides the DEFAULT_PARSER with the UNRESERVED key, including '{' and '}'
  module URI
    def self.parse(uri)
      URI::Parser.new(:UNRESERVED =&gt; URI::REGEXP::PATTERN::UNRESERVED + "\{\}").parse(uri)
    end
  end
  </code></pre>
  
  <p>Now I can use URI.parse(uri) with uri containing curly braces and no error is thrown.</p>