Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call parseUnsafeRelativePath() on non-relative paths. #273

Merged
merged 2 commits into from
Oct 26, 2023
Merged
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
4 changes: 4 additions & 0 deletions url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ func ParseURL(inputURL string, unsafe bool) (*URL, error) {
}
if u.IsRelative {
return ParseRelativePath(inputURL, unsafe)
} else if unsafe {
// we are not relative, but we still need to call this in order to call
// the internal parser for paths url.Parse will not handle.
u.parseUnsafeRelativePath()
}
return u, nil
}
Expand Down
14 changes: 14 additions & 0 deletions url/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ func TestParseFragmentRelativePath(t *testing.T) {
}
}

func TestParseInvalidUnsafe(t *testing.T) {
testcases := []string{
"https://127.0.0.1/%25",
"https://127.0.0.1/%25/aaaa",
"https://127.0.0.1/%25/bb/%45?a=1",
}

for _, input := range testcases {
u, err := ParseURL(input, true)
require.Nilf(t, err, "got error for url %v", input)
require.Equal(t, input, u.String())
}
}

func TestParseParam(t *testing.T) {
testcases := []struct {
inputURL string
Expand Down