Skip to content

securitymedium

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.

name=Ada+Lovelace&lang=py&note=50%25+off
name=Ada Lovelace
lang=py
note=50% off
Learn the technique/learn/web-app-security

main.py