From f1716faa726367602a47d9ce7b1ffda75cff6e2e Mon Sep 17 00:00:00 2001 From: comp500 Date: Mon, 14 Feb 2022 18:47:03 +0000 Subject: [PATCH] Fix URL re-encoding for square brackets --- core/urlutil.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/urlutil.go b/core/urlutil.go index b66f977..0dfb900 100644 --- a/core/urlutil.go +++ b/core/urlutil.go @@ -3,9 +3,15 @@ package core import ( "fmt" "net/url" + "strings" ) +// ReencodeURL re-encodes URLs for RFC3986 compliance; as CurseForge URLs aren't properly encoded func ReencodeURL(u string) (string, error) { + // Go's URL library isn't entirely RFC3986 compliant :( + // Manually replace [ and ] with %5B and %5D + u = strings.ReplaceAll(u, "[", "%5B") + u = strings.ReplaceAll(u, "]", "%5D") parsed, err := url.Parse(u) if err != nil { return "", fmt.Errorf("failed to parse url: %s, %v", u, err)