Open
Description
Previous ID | SR-15632 |
Radar | None |
Original Reporter | @karwa |
Type | Bug |
Environment
Swift 5.5.2, Xcode 13.2, macOS 11.6
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: fc6db48c2ef78af80ca1f0400354939b
Issue Description:
var url = URL(string: "http://[:errwhat/hello")!
print(url.host!) // "[:errwhat"
url = URL(string: "http://[:]errwhat/hello")!
print(url.host!) // ":]errwha"
url = URL(string: "http://errr[:]what/hello")!
print(url.host!) // "rrr[:]wha"
What I suspect is happening is some astonishingly lazy IPv6 parsing - It detects that the hostname contains an opening square bracket, followed a closing square bracket, and so the host should be trimmed of its first and last characters. It doesn't actually check that the opening square bracket is the first character of the hostname, or that the closing square bracket is the last character of the hostname, or that a valid IPv6 address is contained within them.
These URLs should all fail to parse.