Skip to content

Commit

Permalink
fix incorrect url parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Nov 30, 2023
1 parent 0470166 commit de01da7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}()
Expand Down

0 comments on commit de01da7

Please sign in to comment.