Can user input directly cause `URIError: URI malformed` if not explicitly encoded before processing?

Question

Grade: Education Subject: Support
Can user input directly cause `URIError: URI malformed` if not explicitly encoded before processing?
Asked by:
100 Viewed 100 Answers

Answer (100)

Best Answer
(448)
Yes, absolutely. If user input contains a literal '%' character followed by an invalid sequence (e.g., '%A' or '% G') and this string is later passed to `decodeURIComponent()` without prior `encodeURIComponent()` or proper sanitization, it will trigger the 'URI malformed' error. For example, if a user types 'Project progress: 50% complete' and this string is treated as a URI component, the '% c' sequence could lead to the error during decoding.