plus character in forms

So, I have this gaming site, and people have a search form where they can search for game titles. Yesterday, I found a bug with this and I'm unsure where the bug is - with the browser or if there is something I can do.

There is a game called "N+", which is its complete title. But, when searching for that using a form that has GET as the method, the resulting URL will be:


That may look right, but "+" in url's are treated as spaces (even though an url encoded space is %20) and as such, that url would send the value "N " as the search string, which of course wouldn't match the games.

Is there anyting one can do to remedy this?
Who is Participating?
quincydudeConnect With a Mentor Commented:
before submit the form.

you can use the event onsubmit() to make a javascript to replace all presence of the + sign to %2B. Using something like below
<script type="text/javascript">
var replaceStr = "%2B";
var myOldString = "Hello+world+friend";
var myNewString = myOldString.replace(/\+/g, replaceStr );
document.write("Old string =  " + myOldString); 
document.write("<br />New string = " + myNewString);

Open in new window

check and convert it to %2B

whole list of url escape codes
SandmanNetAuthor Commented:
How do I check and convert it? I mean - it's sent as a part of the form submittng. So in the recieving end (the form action target) I get "N ". At what point should I "check and convert it"?
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

SandmanNetAuthor Commented:
Uhm, so you're saying that the only way to remedy this "bug" is to put a javascript handler on every form (since I'd like to remedy this for all forms, not just the game search form)?

That seems like an awfully awkward way of handling things, especially if the user doesn't have JS turned on. Hmmm.
I dun think it's a bug but just some kind of communication mismatch between client and server. The concern is on why the client browser do not encode it and the server side do not decode it properly.

I am just pointing out one possible way to handle this.
And more, nowadays js is already a essential part of web pages, if js is not enabled many page functions simply don't work. Then do you mean you will avoid all tasks made by javascript? If not then your reply of "especially if the user doesn't have JS turned on." doesnt make sense at all.
SandmanNetAuthor Commented:
No, I didn't mean to complain about your solution, I'm sure it works as described. I just expressed a frustration over having to resort to JS to solve a problem you describe as something between the client and server... :/ I'll award you points soon, unless a betetr solution shows up soon enough :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.