diff --git a/url/url.go b/url/url.go index f66566f..b03867d 100644 --- a/url/url.go +++ b/url/url.go @@ -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 } diff --git a/url/url_test.go b/url/url_test.go index 2183356..8f992fe 100644 --- a/url/url_test.go +++ b/url/url_test.go @@ -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