Skip to content

net/url: url.Parse doesn't parse URL with empty schema: www.uber.com/ #27650

@vkuzmin-uber

Description

@vkuzmin-uber

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.11

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

OS X
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

Tried to use url.Parse("www.uber.com/") and extract host in generic way. Appeared that host is empty and path is "www.uber.com/"

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
I looked at Unit Tests and found for instance:

// no path
{
	"http://www.google.com",
	&URL{
		Scheme: "http",
		Host:   "www.google.com",
	},
   }

So, in my case it failed because of empty schema.
I also added a UT for my case and it failed with:

ok net/textproto 0.014s
--- FAIL: TestParse (0.00s)
url_test.go:660: Parse("www.uber.com/"):
got opaque="", scheme="", user=, pass=, host="", path="www.uber.com/", rawpath="", rawq="", frag="", forcequery=false
want opaque="", scheme="", user=, pass=, host="www.uber.com", path="/", rawpath="", rawq="", frag="", forcequery=false

I see url.Parse comment says:

// (starting with a scheme). Trying to parse a hostname and path
// without a scheme is invalid but may not necessarily return an
// error, due to parsing ambiguities.

What did you expect to see?

I think this should be able to parse correctly at least case like mine, this is pretty expected case.

What did you see instead?

Incorrect behavior, w/o error though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions