Skip to content

Commit 9a3828e

Browse files
committed
Merge pull request #5 from pchristopher1275/PatchRemoveDotSegments
This patch allows FlagRemoveDotSegments to work with relative links --
2 parents 1909519 + 1e3a6fe commit 9a3828e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

purell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func removeDotSegments(u *url.URL) {
231231
}
232232
// Special case if host does not end with / and new path does not begin with /
233233
u.Path = strings.Join(dotFree, "/")
234-
if !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") {
234+
if u.Host != "" && !strings.HasSuffix(u.Host, "/") && !strings.HasPrefix(u.Path, "/") {
235235
u.Path = "/" + u.Path
236236
}
237237
// Special case if the last segment was a dot, make sure the path ends with a slash

purell_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,28 @@ var (
653653
"http://test.example/foo/bar/",
654654
false,
655655
},
656+
&testCase{
657+
"Relative-1",
658+
"./../foo",
659+
FlagsSafe | FlagRemoveDotSegments | FlagRemoveDuplicateSlashes,
660+
"foo",
661+
false,
662+
},
663+
&testCase{
664+
"Relative-2",
665+
"./foo/bar/../baz/../bang/..",
666+
FlagsSafe | FlagRemoveDotSegments | FlagRemoveDuplicateSlashes,
667+
"foo/",
668+
false,
669+
},
670+
&testCase{
671+
"Relative-3",
672+
"foo///bar//",
673+
FlagsSafe | FlagRemoveDotSegments | FlagRemoveDuplicateSlashes,
674+
"foo/bar/",
675+
false,
676+
},
677+
656678
/*&testCase{
657679
"UrlNorm-5",
658680
"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",

0 commit comments

Comments
 (0)