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: Parse not working correctly for a non absolute URL with port. #22955

Closed
zbindenren opened this issue Dec 1, 2017 · 4 comments
Closed

Comments

@zbindenren
Copy link

zbindenren commented Dec 1, 2017

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

go version go1.9.1 linux/amd64

Does this issue reproduce with the latest release?

Yes: https://play.golang.org/p/yoLxXnHE1J

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/rz/golang"
GORACE=""
GOROOT="/home/rz/.gimme/versions/go1.9.1.linux.amd64"
GOTOOLDIR="/home/rz/.gimme/versions/go1.9.1.linux.amd64/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build155424131=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

url.Parse not working for relative url with port.

When parsing www.example.com:443, IsAbs returns true, and port is empty.

https://play.golang.org/p/yoLxXnHE1J

What did you expect to see?

IsAbs returns false.

What did you see instead?

IsAbs returns true.

@bradfitz
Copy link
Contributor

bradfitz commented Dec 1, 2017

Dup of #21415

That is not a valid URL. An absolute URL starts with a scheme (http://, etc) and a relative URL must never contain a colon in its first path element, per the specs.

@bradfitz bradfitz closed this as completed Dec 1, 2017
@zbindenren
Copy link
Author

@bradfitz Shouldn't Parse return an error in that case?

@bradfitz
Copy link
Contributor

bradfitz commented Dec 1, 2017

Just keep in mind that you're parsing either a full URL or just a path. Other crap tends to end up in Path or Opaque (https://play.golang.org/p/vbQkLpYwRX) if it's malformed and not one of those forms, but don't depend on how malformed stuff gets parsed.

@gopherbot
Copy link

Change https://golang.org/cl/81436 mentions this issue: net/url: document Parse more

gopherbot pushed a commit that referenced this issue Dec 1, 2017
That Parse doesn't parse ("foo.com/path" or "foo.com:443/path") has
become something of a FAQ.

Updates #19779
Updates #21415
Updates #22955

Change-Id: Ib68efddb67f59b1374e8ed94effd4a326988dee7
Reviewed-on: https://go-review.googlesource.com/81436
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Dec 1, 2018
@mikioh mikioh changed the title url.Parse not working correctly for a non absolute URL with port. net/url: Parse not working correctly for a non absolute URL with port. Feb 26, 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