Javascript decodeURI(Component) malformed uri exception

随声附和 提交于 2019-12-02 20:09:30

%AF is not a character on his own but part of Unicode sequence (MACRON - %C2%AF).

%AF wasn't produced by encodeURIComponent but something like escape, so it can be decoded by unescape.

What you probably need is decodeURIComponent('%C2%AF')

This may or may not apply to someone else's situation but this is what did it for me so I thought I would share. I upload and download lots of text files to a custom CMS.
the '%' sign in the source code was wreaking havoc for me.

// send to server
content = content.toString().replace(/%/g,'~~pct~~')       // ~~pct~~ <-made up replacement
content = encodeURI(content)

// get back from server / database
content = decodeURI(content)
content = content.toString().replace(/~~pct~~/g,'%')       // globally restore '%'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!