-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
78 lines (56 loc) · 1.91 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "URIError: malformed URI sequence"
slug: Web/JavaScript/Reference/Errors/Malformed_URI
page-type: javascript-error
---
{{jsSidebar("Errors")}}
The JavaScript exception "malformed URI sequence" occurs when URI encoding or decoding
wasn't successful.
## Message
```plain
URIError: URI malformed (V8-based)
URIError: malformed URI sequence (Firefox)
URIError: String contained an illegal UTF-16 sequence. (Safari)
```
## Error type
{{jsxref("URIError")}}
## What went wrong?
URI encoding or decoding wasn't successful. An argument given to either the
{{jsxref("decodeURI")}}, {{jsxref("encodeURI")}}, {{jsxref("encodeURIComponent")}}, or
{{jsxref("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
{{jsxref("URIError")}} will be thrown if there is an attempt to encode a surrogate which
is not part of a high-low pair, for example:
```js example-bad
encodeURI("\uD800");
// "URIError: malformed URI sequence"
encodeURI("\uDFFF");
// "URIError: malformed URI sequence"
```
A high-low pair is OK. For example:
```js example-good
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:
```js example-bad
decodeURIComponent("%E0%A4%A");
// "URIError: malformed URI sequence"
```
With proper input, this should usually look like something like this:
```js example-good
decodeURIComponent("JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "JavaScript_шеллы"
```
## See also
- {{jsxref("URIError")}}
- {{jsxref("decodeURI")}}
- {{jsxref("encodeURI")}}
- {{jsxref("encodeURIComponent")}}
- {{jsxref("decodeURIComponent")}}