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: lose keys in url.Query() go 1.10 #24319

Closed
anotherGoogleFan opened this issue Mar 9, 2018 · 2 comments
Closed

net/url: lose keys in url.Query() go 1.10 #24319

anotherGoogleFan opened this issue Mar 9, 2018 · 2 comments

Comments

@anotherGoogleFan
Copy link

anotherGoogleFan commented Mar 9, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\HuangTao\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\GoProject
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\HuangTao\AppData\Local\Temp\go-build137051418=/tmp/go-build -gno-record-gcc-switches

What did you do?

package main

import (
	"fmt"
	"net/url"
)

func main() {
	u := "https://www.example.com?q=5a545a42302f49252189&delivery_id=%DL%&app=%MA%&did=%MI%&channel=WD&slot_id=__clickid__&idfa=%MI%"
	ul, err := url.Parse(u)
	if err != nil {
		panic(err)
	}
	fmt.Println(ul.Query().Encode())
}

What did you expect to see?

q=5a545a42302f49252189&delivery_id=%DL%&app=%MA%&did=%MI%&channel=WD&slot_id=__clickid__&idfa=%MI%

What did you see instead?

channel=WD&q=5a545a42302f49252189&slot_id=__clickid__

the keys (delivery_id, app, did) are lost.

@anotherGoogleFan anotherGoogleFan changed the title net/url: lose key in url.Query() net/url: lose keys in url.Query() go 1.10 Mar 9, 2018
@fraenkel
Copy link
Contributor

fraenkel commented Mar 9, 2018

This is working as designed. Your query params are invalid. But none of the operations you performed will validate them. The docs for url.Query() states that malformed value pairs are discarded.

You could call ParseQuery with the url.RawQuery to validate.

@andybons
Copy link
Member

andybons commented Mar 9, 2018

@fraenkel is correct.

package main

import (
	"fmt"
	"net/url"
)

func main() {
	q, err := url.ParseQuery("q=5a545a42302f49252189&delivery_id=%DL%&app=%MA%&did=%MI%&channel=WD&slot_id=__clickid__&idfa=%MI%")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(q)
}

Outputs:

invalid URL escape "%DL"

@andybons andybons closed this as completed Mar 9, 2018
@golang golang locked and limited conversation to collaborators Mar 9, 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

4 participants