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: parseQuery() better support for array parse. #42293

Closed
ainilili opened this issue Oct 30, 2020 · 5 comments
Closed

net/url: parseQuery() better support for array parse. #42293

ainilili opened this issue Oct 30, 2020 · 5 comments

Comments

@ainilili
Copy link

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

$ 1.15.3

Does this issue reproduce with the latest release?

yes

What did you do?

import (
	"fmt"
	"net/url"
)

func main(){
	query := "params=fo,fu,n%2Cico"
	values, err := url.ParseQuery(query)
	if err != nil{
		panic(err)
	}
	for _, vs := range values{
		for _, v := range vs{
			fmt.Println(v)
		}
	}
}

What did you expect to see?

fo
fu
n,ico

What did you see instead?

fo,fu,n,ico

When an Array parameter is passed by URL or application/ x-www-Form-urlencoded mode, many clients will define the request content in a comma-separated way, so can this expectation be met?

@seankhliao
Copy link
Member

That does not appear to be standard behaviour https://url.spec.whatwg.org/#urlencoded-parsing

And in this case, how would valid values containing commas be preserved?

@imxyb
Copy link
Contributor

imxyb commented Oct 30, 2020

I also think this is more of a business scenario, not suitable for general use

@ainilili
Copy link
Author

That does not appear to be standard behaviour https://url.spec.whatwg.org/#urlencoded-parsing

And in this case, how would valid values containing commas be preserved?

If a valid value needs to contain a comma, just escape it to %2C before initiating the request. But then again, it's not standard.

@ainilili
Copy link
Author

I also think this is more of a business scenario, not suitable for general use

That does not appear to be standard behaviour https://url.spec.whatwg.org/#urlencoded-parsing
And in this case, how would valid values containing commas be preserved?

If a valid value needs to contain a comma, just escape it to %2C before initiating the request. But then again, it's not standard.

However, while this practice is not standard, if it becomes standard, it may be possible to request data transfers:

tags=a&tags=b&tags=c

simplified to:

tags=a,b,c

Of course, this is just a personal thought. xD

@ainilili
Copy link
Author

I also think this is more of a business scenario, not suitable for general use

Well, in order not to break the standards, I should implement this functionality in the application framework layer.

@golang golang locked and limited conversation to collaborators Oct 30, 2021
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