I'm trying to encode URLs in Ruby and decode them with Javascript. However, the plus character is giving me weird behavior.
In Ruby:
[Dev]> CGI.escape "a b"
=> "a+b"
[Dev]> CGI.unescape "a+b"
=> "a b"
So far so good. But what about Javascript?
>>> encodeURI("a b")
"a%20b"
>>> decodeURI("a+b")
"a+b"
Basically I need a method of encoding / decoding URLs that works the same way in Javascript and Ruby.
Edit: decodeURIComponent
is no better:
>>> encodeURIComponent("a b")
"a%20b"
>>> decodeURIComponent("a+b")
"a+b"
CGI.escape
? (Or was it just put there to trick me!) – Zwolle