maddogandnoriko
maddogandnoriko

Reputation: 1002

URL getting coded strangely

I am building a site that allows users to make modifications to some text. I am then building a url so they can come back and their mods will be applied when the page loads. This all works except I am getting some 'funky' characters when I enter the url into the browser address bar.

The url I am putting in is:

http://localhost:8888/PlantTags/index%20copy.php/temp=lg_oval&cn=Common Name&cX=-10&cY=40&cf=Giddyup&cfs=52&clh=1&ca=center&bn=Botanical Name&bX=80&bY=115&bf=Comic-Sans-Ms&bfs=21&blh=1&ba=center&rev=false

But the browser is coding it to:

http://localhost:8888/PlantTags/index%20copy.php?temp=lg_oval&cn=Big%2520Jumbo&cX=-10&cY=40&cf=Giddyup&cfs=52&clh=1&ca=center&bn=Botanical%2520Name&bX=80&bY=115&bf=Comic-Sans-Ms&bfs=21&blh=1&ba=center&rev=false?temp=lg_oval&cn=Big%20Jumbo&cX=-10&cY=40&cf=Giddyup&cfs=52&clh=1&ca=center&bn=Botanical%20Name&bX=80&bY=115&bf=Comic-Sans-Ms&bfs=21&blh=1&ba=center&rev=false

So when I grab the cn parameter from the url I am getting extra characters. Can someone tell me where the %2520 is coming from and what to do about it? I have tried inserting it into a textarea and getting the html from that and decodeURIComponent...both failed. Oh yeah....javascript or jQuery is the chosen language.

Thank you again,

Todd

Upvotes: 0

Views: 283

Answers (3)

Céryl Wiltink
Céryl Wiltink

Reputation: 1909

Well, spaces are not allowed as spaces in URL's, and there is a space in "&cn=Common Name"

A browser will change (Actually URL-encode) all spaces to %20 to send the request. So you need to either change the value in something like "common_name" or something, but your server should also be able to handle that... Another way is to Decode the URL server-side so the %20 get turned back into spaces again and then let it do it's thing

Upvotes: 2

Álvaro González
Álvaro González

Reputation: 146380

If you decode %2520 you get %20. You are encoding some fragments twice.

Upvotes: 2

Sunyatasattva
Sunyatasattva

Reputation: 5830

Try not to use spaces in the URL you are trying to encode, but use hyphens. They will be much more readable and will not get encoded in things like %20 or double encoded in %2520.

Upvotes: 4

Related Questions