URIError: malformed URI sequence - JavaScript 编辑

The JavaScript exception "malformed URI sequence" occurs when URI encoding or decoding wasn't successful.

Message

URIError: The URI to be encoded contains invalid character (Edge)
URIError: malformed URI sequence (Firefox)
URIError: URI malformed (Chrome)

Error type

URIError

What went wrong?

URI encoding or decoding wasn't successful. An argument given to either the decodeURI, encodeURI, encodeURIComponent,  or decodeURIComponent function was not valid, so that the function was unable encode or decode properly.

Examples

Encoding

Encoding replaces each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character. An URIError will be thrown if there is an attempt to encode a surrogate which is not part of a high-low pair, for example:

encodeURI('\uD800');
// "URIError: malformed URI sequence"

encodeURI('\uDFFF');
// "URIError: malformed URI sequence"

A high-low pair is ok. For example:

encodeURI('\uD800\uDFFF');
// "%F0%90%8F%BF"

Decoding

Decoding replaces each escape sequence in the encoded URI component with the character that it represents. If there isn't such a character, an error will be thrown:

decodeURIComponent('%E0%A4%A');
// "URIError: malformed URI sequence"

With proper input, this should usually look like something like this:

decodeURIComponent('JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B');
// "JavaScript_шеллы"

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:110 次

字数:3658

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文