View Full Version : Javascript escape() function and + symbol

12-27-2005, 01:47 PM
Hi everyone,

I am working on a JSP web application using the Spring framework. I am having trouble with URI encoding for form submission when it comes to the javascript escape() function and the + symbol. The symbol is sent to the server unescaped but when it is decoded by the request object on the server side, the + is converted into a space. So for example, if "C++" is submitted in a form, it is decoded on the server side as "C ".

I am wondering if anyone could give me a suggestion for how to solve this problem. Unfortunately using the encodeURI() function is not an option as we are using iso-8859-1 encoding on the server side (it is an intranet application), and changing the server behaviour is not an option for me at this point. Since encodeURI() encodes in UTF-8 format, I end up with this when I use it instead of escape():

Input: développeur
Output: dă©veloppeur

Thanks in advance for any help you can provide!

12-28-2005, 01:28 PM
You could pre-convert the + symbols into something else - something you can recognise and feel confident is unique on the other end, for example something like "~~":

str = str.replace(/(\+\+)/g, '~~');

01-03-2006, 03:45 PM
Thank you very much brothercake, your tip was a huge help. I ended up replacing '+' with the ascii code (%2B) and the server side decoded everything properly. I appreciate the help. :)