Arrays order in URL query params when using same key

When parsing an array from url query params, such as ?id=1&id=2&id=3 with r.ParseForm() which calls parseQuery(), is there a guarantee (whether in go/url or http spec) that the order of the array will be preserved, i.e. id = [1,2,3] will always be returned?

The parseQuery code at the moment will preserve the order but if it’s not guaranteed there is a chance (minuscle or not) that it will change in the future.

I think parsing them out of order would break the semantics of parameter passing. So my opinion is that you are OK here.

Go has a Go 1 compatibility guarantee that likely covers this.

Go 1 and the Future of Go Programs

If it’s essential that this behavior is invariant, add a test that verifies that the invariant holds. If it no longer holds, fail the test with a fatal error.

Thanks both, I think that answered the question

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.