From de01da7a74658e3ca6a0e34dc7f9cb14024be2ad Mon Sep 17 00:00:00 2001 From: Ramana Reddy Date: Thu, 30 Nov 2023 18:07:49 +0530 Subject: [PATCH] fix incorrect url parsing --- url/url.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/url/url.go b/url/url.go index 2c8ee66..bb0c1a4 100644 --- a/url/url.go +++ b/url/url.go @@ -14,6 +14,11 @@ import ( // Ex: if input is admin url.Parse considers admin as host which is not a valid domain name var DisableAutoCorrect bool +// disables autocorrect related to url.path +// Ex: if input is admin url.Parse considers admin as path(when DisableAutoCorrect is false) and adds missing prefix('/') +// On setting DisablePathAutoCorrection to true prefix is not added +var DisablePathAutoCorrection bool + // URL a wrapper around net/url.URL type URL struct { *url.URL @@ -172,7 +177,7 @@ func (u *URL) parseUnsafeRelativePath() { // ex: /%20test%0a =? // autocorrect if prefix is missing defer func() { - if !strings.HasPrefix(u.Path, "/") && u.Path != "" { + if !DisablePathAutoCorrection && !strings.HasPrefix(u.Path, "/") && u.Path != "" { u.Path = "/" + u.Path } }()