stretchr / objx

Go package for dealing with maps, slices, JSON and other data.
MIT License
691 stars 75 forks source link

URLQuery with index slice keys #74

Closed geseq closed 6 years ago

geseq commented 6 years ago

Certain APIs (I believe those written in PHP) seem to be unable to parse correctly URLQuery() result containing slices generated by URLValuesSliceKeySuffix="" or URLValuesSliceKeySuffix="[]".

The solution is to pass the slices with an index so that they are read correctly.

For instance, in order to parse slices of the form correctly: objx.Map{"mapSlice": []objx.Map{objx.Map{"age": 40, "sex": "male"}, objx.Map{"height": 152}}} the query needs to be: mapSlice[0][age]=40&mapSlice[0][sex]=male&mapSlice[1][height]=152

Currently these two forms are possible which don't work: mapSlice[age]=40&mapSlice[sex]=male&mapSlice[height]=152 mapSlice[][age]=40&mapSlice[][sex]=male&mapSlice[][height]=152

I've modified the code to check for URLValuesSliceKeySuffix="[i]" and use slice indexes when present

geseq commented 6 years ago

Added tests wrt #71 but I will write additional tests separately.

hanzei commented 6 years ago

@earncef Could give this a rebase?

geseq commented 6 years ago

Done

geseq commented 6 years ago

I agree. What would you consider the case for error though? Not being one of "" or "[]" or "[I]"?

geseq commented 6 years ago

@Hanzei any update on the last commit?

hanzei commented 6 years ago

I agree. What would you consider the case for error though? Not being one of "" or "[]" or "[I]"?

Correct. I would limit SetURLValuesSliceKeySuffix to these three values and throw an error for every other.

geseq commented 6 years ago

Done