Previously if a path was set manually without a leading /, String()
would not insert the slash when writing its output. This would lead
to situations where a URL that should be http://www.google.com/search
is output as http://www.google.comsearch
Fixes #5927.
R=golang-dev, bradfitz, rsc, 0xjnml
CC=golang-dev
https://golang.org/cl/
11698045
buf.WriteString(h)
}
}
+ if u.Path != "" && u.Path[0] != '/' {
+ buf.WriteByte('/')
+ }
buf.WriteString(escape(u.Path, encodePath))
}
if u.RawQuery != "" {
func TestURLString(t *testing.T) {
DoTestString(t, Parse, "Parse", urltests)
+
+ // no leading slash on path should prepend
+ // slash on String() call
+ noslash := URLTest{
+ "http://www.google.com/search",
+ &URL{
+ Scheme: "http",
+ Host: "www.google.com",
+ Path: "search",
+ },
+ "",
+ }
+ s := noslash.out.String()
+ if s != noslash.in {
+ t.Errorf("Expected %s; go %s", noslash.in, s)
+ }
}
type EscapeTest struct {