refine url normalization

Before, the entire url was being lowercased, which mutilates various case-sensitive parts.
Now, only the host gets lowercased, and the test verify that the userinfo, path, and query parts preserve their original case.
This commit is contained in:
Jay
2026-08-11 11:44:36 -04:00
parent d50ec56800
commit 53cb949d2b
2 changed files with 22 additions and 1 deletions
+6 -1
View File
@@ -22,13 +22,18 @@ func ParseURL(urlStr string) (*url.URL, error) {
}
func NormalizeURL(input string) (string, error) {
parsed, err := ParseURL(strings.ToLower(input))
parsed, err := ParseURL(input)
if err != nil {
return "", err
}
// lowercase host
parsed.Host = strings.ToLower(parsed.Host)
host := parsed.Hostname()
port := parsed.Port()
// strip default ports
if (parsed.Scheme == "wss" && port == "443") ||
(parsed.Scheme == "ws" && port == "80") {
parsed.Host = host