fjordtools / Errors / URIError: URI malformed

URIError: URI malformed

decodeURIComponent found a percent sign that is not followed by two hex digits, or a run of escapes that is not valid UTF-8. A plain 100% in the text is enough. Encode a literal percent sign as %25 before it goes into a URL, and only decode text that was encoded first.

Fjordtools team · Seen in Chrome and Node (V8) · Published · 1 min read

How browsers word it

Chrome and Node (V8)URIError: URI malformed
FirefoxURIError: malformed URI sequence
SafariURIError: URI error

Common causes

  1. 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
  2. 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
  3. 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
  4. 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

  1. Encode a literal % as %25, with encodeURIComponent, before it goes into a URL.
  2. Do not decode the same text twice, and do not decode text that was never encoded.
  3. Wrap decodeURIComponent in a try and fall back to the raw text for input you do not control.
  4. Paste the text into the URL encoder to see where the broken sequence is.

Related errors

More error explainers are coming

See all errors.