Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vkuzmin-uber opened this issue Sep 13, 2018 · 2 comments
Closed

Comments

@vkuzmin-uber
Copy link
Contributor

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.

@vkuzmin-uber
Copy link
Contributor Author

I am willing to provide fix if there are no objections. I already have Unit Test for my case and work on change.

@dominikh
Copy link
Member

dominikh commented Sep 13, 2018

Sort of a duplicate of #12585, in any case working as intended. url.Parse is for parsing URLs; a URL starts with a scheme.

The point the comment is making that invalid URLs can look like valid URLs, for example localhost:1111 looks like a URL with the scheme localhost – it doesn't mean that url.Parse should go out of its way to support (guess!) certain invalid URLs.

@mikioh mikioh changed the title net: url.Parse doesn't parse URL with empty schema: www.uber.com/ net/url: url.Parse doesn't parse URL with empty schema: www.uber.com/ Sep 13, 2018
@golang golang locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants