Skip to content

Commit

Permalink
Merge pull request #5 from pchristopher1275/PatchRemoveDotSegments
Browse files Browse the repository at this point in the history
This patch allows FlagRemoveDotSegments to work with relative links --
  • Loading branch information
mna committed Jan 22, 2015
2 parents 1909519 + 1e3a6fe commit 9a3828e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion purell.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func removeDotSegments(u *url.URL) {
}
// Special case if host does not end with / and new path does not begin with /
u.Path = strings.Join(dotFree, "/")
if !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") {
if u.Host != "" && !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") {
u.Path = "/" + u.Path
}
// Special case if the last segment was a dot, make sure the path ends with a slash
Expand Down
22 changes: 22 additions & 0 deletions purell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,28 @@ var (
"http://test.example/foo/bar/",
false,
},
&testCase{
"Relative-1",
"./../foo",
FlagsSafe | FlagRemoveDotSegments | FlagRemoveDuplicateSlashes,
"foo",
false,
},
&testCase{
"Relative-2",
"./foo/bar/../baz/../bang/..",
FlagsSafe | FlagRemoveDotSegments | FlagRemoveDuplicateSlashes,
"foo/",
false,
},
&testCase{
"Relative-3",
"foo///bar//",
FlagsSafe | FlagRemoveDotSegments | FlagRemoveDuplicateSlashes,
"foo/bar/",
false,
},

/*&testCase{
"UrlNorm-5",
"http://ja.wikipedia.org/wiki/%E3%82%AD%E3%83%A3%E3%82%BF%E3%83%94%E3%83%A9%E3%83%BC%E3%82%B8%E3%83%A3%E3%83%91%E3%83%B3",
Expand Down

0 comments on commit 9a3828e

Please sign in to comment.