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: should *User methods return zero values when called with a nil receiver? #20924

Closed
kindlychung opened this issue Jul 6, 2017 · 5 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Milestone

Comments

@kindlychung
Copy link

kindlychung commented Jul 6, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 linux/amd64

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

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

What did you do?

https://play.golang.org/p/3yO2OL-XTq

What did you expect to see?

I would like to have something like username, err := url.User.Username() and handle the error if there is no username in the url.

What did you see instead?

A panic.

@bradfitz bradfitz changed the title url.User.Username() should return error when no username is in url net/url: url.User.Username() should return error when no username is in URL Jul 6, 2017
@bradfitz bradfitz added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jul 6, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Jul 6, 2017
@bradfitz bradfitz changed the title net/url: url.User.Username() should return error when no username is in URL net/url: should *User methods return zero values when called with a nil receiver? Jul 6, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Jul 6, 2017

I could see some argument for (*Userinfo).Password and (*Userinfo).Username to return zero values when called with a nil receiver instead of panicking.

Leaving open to decide during Go 1.10.

@bradfitz
Copy link
Contributor

bradfitz commented Jul 6, 2017

That is, we could make this work:

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

package main

import "net/url"

func main() {
	u, err := url.Parse("http://foo.com/")
	if err != nil {
		panic(err)
	}
	println("URL username is ...")
	println(u.User.Username())
}

@gopherbot
Copy link

CL https://golang.org/cl/47851 mentions this issue.

@bradfitz
Copy link
Contributor

Has CL, so added release-blocked label.

@bradfitz
Copy link
Contributor

bradfitz commented Nov 2, 2017

@rsc, thoughts? I'm fine with this but don't feel strongly.

@golang golang locked and limited conversation to collaborators Nov 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants