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.
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..
Save this question.
Run your string through encodeURIComponent()
. Then components that truncate would be encoded. Afterwards when retrieving the data you need to decode.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With