How to detect if a string is encoded with escape() or encodeURIComponent()

后端 未结 5 1022
误落风尘
误落风尘 2020-12-31 11:48

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

5条回答
  •  暖寄归人
    2020-12-31 12:28

    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.

提交回复
热议问题