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

13,967

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.

Share:
13,967
Kevin Burke
Author by

Kevin Burke

I build reliable software and design great experiences. I'm available for hire: https://burke.services

Updated on June 26, 2022

Comments

  • Kevin Burke
    Kevin Burke almost 2 years

    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?

  • Kevin Burke
    Kevin Burke over 13 years
    I tried removing all of the Javascript from the offending page and still got the 404 error. I also tried running it in MAMP and did not get an error. Does that help narrow the problem down?
  • SakthiSureshAnand
    SakthiSureshAnand almost 6 years
    @Michael Pryor , can i use encodeUri() to convert that percentage or the whole url then send to back end like this , assume I am writing this in GET request ajax $.ajax({ type : 'GET' , url: encodeURI(baseUrl+'/'+'GATE -I- %04') }) is it good practice , because my user key in data may special characters like %, & , _ ,- . I have read the post encodeUri , encodeUri component but could not undertood which is best to use for the spcial characters . Please guide me .