最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - decodeURIComponent throwing an error 'URI malformed' - Stack Overflow

programmeradmin3浏览0评论

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

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 ?

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

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 ?

Share Improve this question edited Mar 8, 2016 at 8:46 vimal1083 asked Jan 21, 2015 at 9:34 vimal1083vimal1083 8,6816 gold badges35 silver badges50 bronze badges 5
  • please post the error – roryok Commented Jan 21, 2015 at 9:36
  • @roryok — "URI malformed" – Quentin Commented Jan 21, 2015 at 9:37
  • i am getting URIError: URI malformed , try this in console decodeURIComponent('Coast%20Guard%20Academy%20to%20hold%20annual%20Women%92s%20%91Leadhership%92%20event') – vimal1083 Commented Jan 21, 2015 at 9:37
  • The issue is with the %91 and %92 characters - the quotes. I'm not sure on exactly why this is – Rory McCrossan Commented Jan 21, 2015 at 9:38
  • Consider this solution:stackoverflow./a/45732650/4572425 – Dudi Commented Aug 17, 2017 at 10:30
Add a ment  | 

1 Answer 1

Reset to default 3

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 putes 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.

发布评论

评论列表(0)

  1. 暂无评论