URIError 🟨 JavaScript

URIError: URI malformed

decodeURIComponent/decodeURI received an invalid percent-encoded sequence.

Seen on: JavaScript

Meaning

A stray % (like "50%off") or a truncated %E2%82 sequence makes decoding fail.

Common causes

  • Literal % in data not encoded
  • Double-decoding already decoded values
  • Truncated UTF-8 percent sequences

⚡ Quick fix

  1. Encode with encodeURIComponent when building URLs
  2. Decode only once
  3. Wrap decoding in try/catch

Detailed fix by platform

JavaScript

  1. function safeDecode(s) { try { return decodeURIComponent(s); } catch { return s; } }

How to diagnose

  1. Input — Which string failed?
  2. Encoding — Encoded/decoded how many times?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.