Hi guys, I have a web service that receives data from various clients. Some of them sends the data encoded using escape(), while the others instead use encodeURIComponent(). Is there a way to detect the encoding used to escape the data?
views:
375answers:
2
+1
A:
Encourage your clients to use encodeURIComponent(). See this page for an explanation: Comparing escape(), encodeURI(), and encodeURIComponent(). If you really want to try to figure out exactly how something was encoded, you can try to look for some of the characters that escape() and encodeURI() do not encode.
Swingley
2009-08-14 03:54:02
I agree that, but unfortunately I can't force the clients to adopt a encoding standard.
Rodrigo
2009-08-15 21:35:47
A:
You don't have to differentiate them. escape() is so called percent encoding, it only differs from URI encoding in how certain chars encodes. For example, Space is encoded as %20 with escape but + with URI encoding. Once decoded, you always get the same value.
ZZ Coder
2009-08-14 05:37:42