Kevin Burke
Kevin Burke

Reputation: 64854

Why does a percent symbol in a get request break my site?

I feel pretty stupid for asking this, but I'm doing a form where the user enters some input and sometimes the input is a percent symbol, say 5%. When this gets passed along as part of a GET request, like this:

http://kburke.org/project/company_x/?id=4&var1=1&ops=23255&cashflow=25000&growth=5%25&pv=100000&roe=20&profitmargin=30&roe=80&turnover=2

I get a 404 Page Not Found error. When I remove the query string pair

&growth=5%25

the page loads fine. Can someone help explain what the problem is?

Edit: I tried removing all of the Javascript from the page and the server still craps out. I also just tried running it in MAMP as

http://localhost:8888/project/company_x/?id=4&var1=1&ops=23255&cashflow=25000&growth=5%25&pv=100000&roe=20&profitmargin=30&roe=80&turnover=2

and it worked fine. I'm wondering if it's a problem with my own server. When I open Firebug to the console and run the page, I see an error very briefly and then the 404 page loads - is there a way I can pause the redirect so I can read the error message?

Upvotes: 8

Views: 18113

Answers (1)

Michael Pryor
Michael Pryor

Reputation: 25346

Check out URL ENCODING. The "%" character in a url means something special.

You encode the space character ' ' as %20 in a url. You encode the percent character '%' as %25 in a url.

So after your url gets to the script, your argument 'growth' will equal "5%".

I tried messing around with your url and it appears that your script is crashing when it tries to parse the growth argument, and your web site is hiding that crash from you by sending you to the 404 page. I'd post your script code if you need more help.

Upvotes: 14

Related Questions