// parseHost parses host as an authority without user
// information. That is, as host[:port].
func parseHost(scheme, host string) (string, error) {
- if openBracketIdx := strings.LastIndex(host, "["); openBracketIdx != -1 {
+ if openBracketIdx := strings.LastIndex(host, "["); openBracketIdx > 0 {
+ return "", errors.New("invalid IP-literal")
+ } else if openBracketIdx == 0 {
// Parse an IP-Literal in RFC 3986 and RFC 6874.
// E.g., "[fe80::1]", "[fe80::1%25en0]", "[fe80::1]:80".
closeBracketIdx := strings.LastIndex(host, "]")
{"http://[fe80::1", true}, // missing closing bracket
{"http://fe80::1]/", true}, // missing opening bracket
{"http://[test.com]/", true}, // domain name in brackets
+ {"http://example.com[::1]", true}, // IPv6 literal doesn't start with '['
+ {"http://example.com[::1", true},
+ {"http://[::1", true},
+ {"http://.[::1]", true},
+ {"http:// [::1]", true},
+ {"hxxp://mathepqo[.]serveftp(.)com:9059", true},
}
for _, tt := range tests {
u, err := Parse(tt.in)