Skip to content

net/url: regression from issue 11698045 #6609

@gopherbot

Description

@gopherbot

by raff367:

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.

The test at http://play.golang.org/p/Yzayz9Fmuy returns different values in Go 1.2 vs.
Go 1.1.2

func main() {
        path := "a/b/c"
        u, _ := url.Parse(path)
        fmt.Println("path:", path)
        fmt.Println("url:", u.String())
 }

What is the expected output?

"a/b/c"

What do you see instead?

"/a/b/c"

Which version are you using?  (run 'go version')

go version devel +f4d1cb8d9a91 Thu Sep 19 22:34:33 2013 +1000 darwin/amd64

Please provide any additional information below.

The problem is caused by the "fix" for issue #11698045, that prepends a
"/" to the path in the String() method.
The correct fix is, I believe, to check if the buffer is empty or not. If it's empty the
original URL was a "relative URL" (no schema, no host, only path) in which
case the "/" should be omitted.

I have tested a fix, avaliable at https://golang.org/cl/14654045/
I have also updated the tests and added a new unit tests for similar cases ( build the
URL{} and check if String() returns the expected value)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions