The brackets that hide a host
A URL parser treats bracketed domain names and IPv4 addresses as valid IP literals.
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
["[example.com]"]
[null]
["[::1]:443","Example.COM:80"]
["::1","example.com"]
["[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.
Read the report, then sign in to start your investigation.