FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go/


Description:
net/url: fix handling of relative paths in ResolveReference.

Fixes issue 3560.

Please review this at https://codereview.appspot.com/6886047/

Affected files:
M src/pkg/net/url/url.go
M src/pkg/net/url/url_test.go


Index: src/pkg/net/url/url.go
===================================================================
--- a/src/pkg/net/url/url.go
+++ b/src/pkg/net/url/url.go
@@ -572,23 +572,32 @@
if len(base) == 0 {
base = []string{""}
}
+
+ ndot := 1
for idx, ref := range refs {
switch {
case ref == ".":
- base[len(base)-1] = ""
+ if ndot == 1 {
+ base[len(base)-1] = ""
+ }
+ ndot = 1
case ref == "..":
newLen := len(base) - 1
if newLen < 1 {
newLen = 1
}
base = base[0:newLen]
- base[len(base)-1] = ""
+ if ndot > 0 {
+ base[len(base)-1] = ""
+ }
+ ndot = 2
default:
if idx == 0 || base[len(base)-1] == "" {
base[len(base)-1] = ref
} else {
base = append(base, ref)
}
+ ndot = 0
}
}
return strings.Join(base, "/")
Index: src/pkg/net/url/url_test.go
===================================================================
--- a/src/pkg/net/url/url_test.go
+++ b/src/pkg/net/url/url_test.go
@@ -536,6 +536,11 @@
{"http://foo.com/bar/baz", "../../../../../quux", "http://foo.com/quux"},
{"http://foo.com/bar", "..", "http://foo.com/"},
{"http://foo.com/bar/baz", "./..", "http://foo.com/"},
+ // ".." in the middle (issue 3560)
+
{"http://foo.com/bar/baz", "quux/dotdot/../tail", "http://foo.com/bar/quux/tail"},
+
{"http://foo.com/bar/baz", "quux/./dotdot/../tail", "http://foo.com/bar/quux/tail"},
+
{"http://foo.com/bar/baz", "quux/./dotdot/.././tail", "http://foo.com/bar/quux/tail"},
+
{"http://foo.com/bar/baz", "quux/./dotdot/../dotdot/../dot/./tail/..", "http://foo.com/bar/quux/dot"},

// "." and ".." in the base aren't special

{"http://foo.com/dot/./dotdot/../foo/bar", "../baz", "http://foo.com/dot/./dotdot/../baz"},

Search Discussions

  • Russ Cox at Dec 7, 2012 at 3:46 am
    Please add a case with ./.. in the middle
  • Rickarnoldjr at Dec 7, 2012 at 3:23 pm
    PTAL
    Please add a case with ./.. in the middle
    Done. Also added some runs such as "./../../.././././" which led me to a
    slightly simpler implementation.


    https://codereview.appspot.com/6886047/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 6, '12 at 11:28a
activeDec 7, '12 at 3:23p
posts3
users2
websitegolang.org

2 users in discussion

Rickarnoldjr: 2 posts Russ Cox: 1 post

People

Translate

site design / logo © 2022 Grokbase