Safe Query Parser
175 points · 0 solved
Parse one URL query string (no leading ?).
- Split on
&and skip empty segments. - Split each segment at the first
=; with no=, the value is empty. - Decode key and value:
+becomes a space, then%XX(two hex digits, any case) becomes that byte. A%not followed by two hex digits stays as a literal%. - Skip pairs whose decoded key is empty.
Print key=value for each pair in order, or EMPTY if there are none. All decoded bytes are printable ASCII.
Example 1 input
name=Ada+Lovelace&lang=py¬e=50%25+off
Expected output
name=Ada Lovelace lang=py note=50% off
main.py
Ctrl+Enter runs · Ctrl+Shift+Enter submits