Hashing, encoding and basic security · 12 / 15 Exercise Medium

Take a URL apart

Objective

URLs have a precise structure, and splitting them with split or with home-made regular expressions is a classic source of bugs and security flaws. urllib.parse.urlparse does it properly, and parse_qsl decodes the parameters (including %20 and +).

Instructions

  • The input is a line with a URL.
  • Show Scheme: ..., Host: ..., Port: ... (or - if there is none), Path: ... (or / if empty) and then a Parameter: key=value for each query parameter, sorted.
Input
https://ejemplo.com:8443/buscar?q=python&pagina=2
Output
Scheme: https
Host: ejemplo.com
Port: 8443
Path: /buscar
Parameter: pagina=2
Parameter: q=python

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise