How browsers word it
| Chrome and Node (V8) | URIError: URI malformed |
|---|---|
| Firefox | URIError: malformed URI sequence |
| Safari | URIError: URI error |
Common causes
A literal percent sign
Text such as a discount or a progress value contains a % that was never encoded.
Input
100%
URL Encoder says
Not valid: the text contains a broken % sequence or an unpaired surrogate character
Letters that are not hex digits
A percent sign must be followed by two characters from 0 to 9 and a to f.
Input
%zz
URL Encoder says
Not valid: the text contains a broken % sequence or an unpaired surrogate character
A cut-off escape sequence
A multi-byte character such as an accented letter is written as several escapes. If the end is cut off, the last one is incomplete.
Input
%E0%A4%A
URL Encoder says
Not valid: the text contains a broken % sequence or an unpaired surrogate character
The encoded form works
A literal percent sign written as %25 decodes back to a percent sign.
Input
100%25
URL Encoder says
100%
How to fix it
- Encode a literal % as %25, with encodeURIComponent, before it goes into a URL.
- Do not decode the same text twice, and do not decode text that was never encoded.
- Wrap decodeURIComponent in a try and fall back to the raw text for input you do not control.
- Paste the text into the URL encoder to see where the broken sequence is.