title: Why doesn't decodeURI("a+b") == "a b"?
body: <p>I'm trying to encode URLs in Ruby and decode them with Javascript. However, the plus character is giving me weird behavior.</p>
  
  <p>In Ruby:</p>
  
  <pre><code>[Dev]&gt; CGI.escape "a b"
  =&gt; "a+b"
  [Dev]&gt; CGI.unescape "a+b"
  =&gt; "a b"
  </code></pre>
  
  <p>So far so good. But what about Javascript?</p>
  
  <pre><code>&gt;&gt;&gt; encodeURI("a b")
  "a%20b"
  &gt;&gt;&gt; decodeURI("a+b")
  "a+b"
  </code></pre>
  
  <p>Basically I need a method of encoding / decoding URLs that works the same way in Javascript and Ruby.</p>
  
  <p><strong>Edit:</strong> <code>decodeURIComponent</code> is no better:</p>
  
  <pre><code>&gt;&gt;&gt; encodeURIComponent("a b")
  "a%20b"
  &gt;&gt;&gt; decodeURIComponent("a+b")
  "a+b"
  </code></pre>