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 User field is not JSON marshaled #33431

Closed
doppioandante opened this issue Aug 2, 2019 · 3 comments
Closed

net/url: URL User field is not JSON marshaled #33431

doppioandante opened this issue Aug 2, 2019 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@doppioandante
Copy link

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

$ go version
go version go1.12.7 linux/amd64

Does this issue reproduce with the latest release?

Didn't test

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/lavoro/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/lavoro/apps/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.12"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.12/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build187346097=/tmp/go-build -gno-record-gcc-switches"

Playground: https://play.golang.org/p/8u1idvEZNKp

package main

import (
	"encoding/json"
	"fmt"
	"net/url"
)

func main() {
	urlStr := "ssh://git:pw@gitlab.test:test/test.git"
	ur, _ := url.Parse(urlStr)
	s, _ := json.Marshal(ur)
	var ur2 *url.URL
	json.Unmarshal(s, &ur2)
	fmt.Println(ur)
	fmt.Println(ur2)

}
@doppioandante doppioandante changed the title net.URL User field is not encoded correnctly in json net.URL User field is not encoded correctly in json Aug 2, 2019
@agnivade
Copy link
Contributor

agnivade commented Aug 2, 2019

It is being encoded correctly. Just that User does not have its fields exported. So you are getting a "{}". You need to define your own marshal method, or just pass the string representation of the url directly to wherever you were sending the json data. This is WAI.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 2, 2019
@odeke-em odeke-em changed the title net.URL User field is not encoded correctly in json net/url: URL User field is not JSON marshaled Aug 4, 2019
@doppioandante
Copy link
Author

I think I will go with the "use the whole URL" approach in my use case. What are the disadvantages of putting a default marshal method for the User field in the standard library?

@agnivade
Copy link
Contributor

agnivade commented Aug 5, 2019

What are the disadvantages of putting a default marshal method for the User field in the standard library?

Any new API needs to have sufficient justification to be added. As of now, there seems to be a easy enough workaround to the issue. However, if you think such a method should be added, please feel free to file a proposal, and we can let the discussion happen over there. I will close this one since this issue is WAI.

@agnivade agnivade closed this as completed Aug 5, 2019
@golang golang locked and limited conversation to collaborators Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants