Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSTs that contain a semicolon are cut off after semicolon

If I have a POST parameter of

d={"data": "<span>hello</span>"}

which is a JSON string and it works fine and request.POST.get('d') contains the full string. But if I change it to

d = {"data": "<span>hel;lo</span>"}
print (request.POST.get('d')) #prints '{"data": "<span>hel'

For some reason anything after a semicolon is cut off. I can confirm this is not Javascript doing this because I used to use the exact same javascript code to post to a PHP API which was able to retrieve the data. Since moving to Python and webapp2 I've had this issue.

like image 926
Michael Bates Avatar asked Nov 15 '12 08:11

Michael Bates


People also ask

Is semicolon allowed in URL?

Yes, semicolons are valid in URLs. However, if you're plucking them from relatively unstructured prose, it's probably safe to assume a semicolon at the end of a URL is meant as sentence punctuation. The same goes for other sentence-punctuation characters like periods, question marks, quotes, etc..

Which character replaces a semicolon in any portion of the URL string?

Save this question.


2 Answers

Run your string through encodeURIComponent(). Then components that truncate would be encoded. Afterwards when retrieving the data you need to decode.

like image 52
Konstantin Dinev Avatar answered Sep 28 '22 07:09

Konstantin Dinev


This depends on the Content-Type of the request. If content type is application/x-www-form-urlencoded then you need to urlencode the params. See first answer for a detailed explanation: application/x-www-form-urlencoded or multipart/form-data?

like image 30
Peter Knego Avatar answered Sep 28 '22 07:09

Peter Knego