bugger.
All challenges/Pythonmediumthe-brackets-that-hide-a-host-v1
THE INVESTIGATION

The brackets that hide a host

A URL parser treats bracketed domain names and IPv4 addresses as valid IP literals.

ParsingSecurityProtocols

What’s going wrong

A host extractor accepts text inside brackets without checking which kind of host it represents. Different URL consumers can then disagree.

Input is an array of host authorities without credentials. Print the lowercase extracted host or null. Unbracketed hosts use [A-Za-z0-9.-]+ and an optional colon plus ASCII decimal port 0..65535. Bracketed hosts must contain a valid IPv6 address without a percent scope identifier, or an IPvFuture literal matching v + one or more hex version digits + . + one or more ASCII unreserved/sub-delimiter/colon characters. The prefix v is case insensitive. Brackets may be followed only by the same optional port. Domain names and IPv4 addresses do not become IP literals merely by adding brackets. The unbracketed grammar is deliberately a small teaching grammar.

Expected behavior

Validate the host type promised by bracket syntax before returning its value, retaining valid IPv6 and IPvFuture hosts.

Reproduction

01 Bracketed domain
["[example.com]"]
[null]
02 Ordinary IPv6 and host
["[::1]:443","Example.COM:80"]
["::1","example.com"]
03 Valid IPvFuture
["[v1.a:b]","[VF.a-b]:0"]
["v1.a:b","vf.a-b"]

Before you begin

  • Regular expressions
  • URL components
  • IPv4 and IPv6

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.