decodeURIComponent throwing an error 'URI malformed'

一个人想着一个人 提交于 2019-12-11 12:17:55

问题


As unescape has been deprecated I have chosen decodeURIComponent , but it doesn't work as expected . decodeURIComponent cant decode the following URI component

Coast%20Guard%20Academy%20to%20hold%20annual%20Women%92s%20%91Leadhership%92%20event

While decoding the above string decodeURIComponent throws an error, which blocks the remaining javascript execution.

Is there is any solution to fix this ?


回答1:


The %91 and %92 characters were encoded using an ANSI codepage. decodeURIComponent() expects the string to have been encoded as UTF-8:

The decodeURIComponent function computes a new version of a URI in which each escape sequence and UTF-8 encoding of the sort that might be introduced by the encodeURIComponent function is replaced with the character that it represents.

The two quotes should be encoded as %E2%80%98 and %E2%80%99.



来源:https://stackoverflow.com/questions/28063750/decodeuricomponent-throwing-an-error-uri-malformed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!