Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/next/6-stdlib/99-minor/net/url/78569.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[URL.Hostname] and [URL.Port] now follow RFC 6874 more strictly by
forbidding unescaped non-unreserved characters in IPv6 zone identifiers.
[#78569](/issue/78569)
34 changes: 17 additions & 17 deletions src/net/url/encoding_table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/net/url/gen_encoding_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func shouldEscape(c byte, mode encoding) bool {
return false
}

if mode == encodeHost || mode == encodeZone {
if mode == encodeHost {
// §3.2.2 Host allows
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
// as part of reg-name.
Expand All @@ -172,6 +172,21 @@ func shouldEscape(c byte, mode encoding) bool {
}
}

if mode == encodeZone {
// RFC 6874 §2 defines:
// ZoneID = 1*( unreserved / pct-encoded )
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
// ALPHA and DIGIT are already handled above.
// All other characters — including sub-delims like "!" and
// gen-delims like "]" — must be percent-encoded, not raw.
switch c {
case '-', '.', '_', '~':
return false
}
return true
}


switch c {
case '-', '_', '.', '~': // §2.3 Unreserved characters (mark)
return false
Expand Down
6 changes: 6 additions & 0 deletions src/net/url/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,12 @@ var parseRequestURLTests = []struct {
{"http://[fe80::%31]:8080/", false},
{"http://[fe80::%31%25en0]/", false},
{"http://[fe80::%31%25en0]:8080/", false},
{"http://[::1%25]evil.com]", false},
{"http://[::1%25]evil.com]:80", false},
{"http://[fe80::1%25!]/", false},
{"http://[fe80::1%25$]/", false},
{"http://[fe80::1%25&]/", false},


// These two cases are valid as textual representations as
// described in RFC 4007, but are not valid as address
Expand Down