title: Ruby 1.9.3 add unsafe characters to URI.escape
body: <p>I am using Sinatra and get parameters from the url using the <code>get '/foo/:bar' {}</code> method. Unfortunately, the value in <code>:bar</code> can contain nasty things like <code>/</code> which leads to an 404, since no route matches <code>/foo/:bar/baz</code>/. I use <code>URI.escape</code> to escape the URL paramter, but it considers <code>/</code> valid a valid character. As it is mentioned <a href="http://usernameguy.livejournal.com/3495.html" rel="nofollow">here</a> this is because the default Regexp to check against does not differentiate between unsafe and reserved characters. I would like to change this and did this:</p>
  
  <pre><code>URI.escape("foo_&lt;_&gt;_&amp;_3_#_/_+_%_bar", Regexp.union(URI::REGEXP::UNSAFE, '/'))
  </code></pre>
  
  <p>just to test it.</p>
  
  <p><code>URI::REGEXP::UNSAFE</code> is the default regexp to match against according to the <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI/Escape.html#method-i-escape" rel="nofollow">Ruby 1.9.3 Documentaton</a>:</p>
  
  <pre class="lang-none prettyprint-override"><code>escape(*arg)
  Synopsis
      URI.escape(str [, unsafe])
  
  Args
      str
          String to replaces in.
      unsafe
          Regexp that matches all symbols that must be replaced with
          codes. By default uses REGEXP::UNSAFE. When this argument is
          a String, it represents a character set.
  Description
      Escapes the string, replacing all unsafe characters with codes.
  </code></pre>
  
  <p>Unfortunatelly I get this error:</p>
  
  <pre><code>uninitialized constant URI::REGEXP::UNSAFE
  </code></pre>
  
  <p>And as <a href="https://github.com/ripienaar/graphite-graph-dsl/issues/19" rel="nofollow">this GitHub Issue</a> suggests, this Regexp was removed from Ruby with 1.9.3. Unfortunately, the <code>URI</code> modules documentation is generally kind of bad, but I really cannot figure this out. Any hints?</p>
  
  <p>Thanks in advance!</p>