URLQuery with index slice keys#74
URLQuery with index slice keys#74hanzei merged 7 commits intostretchr:masterfrom geseq:URLQuery-Index-Slice-Key
Conversation
|
Added tests wrt #71 but I will write additional tests separately. |
|
@earncef Could give this a rebase? |
|
Done |
hanzei
left a comment
There was a problem hiding this comment.
Nice work! I really like the suffix [i] option. But I dont think exposing this option via a variable is correct. A function seems to be the a better way. I would go with func SetURLValuesSliceKeySuffix(s string) error
| @@ -131,25 +148,42 @@ func (m Map) parseURLValues(queryMap Map, vals url.Values, key string) { | |||
| m.parseURLValues(New(v), vals, key+"["+k+"]") | |||
| } | |||
| case val.IsMSISlice(): | |||
There was a problem hiding this comment.
This case isn't covered by any testcases. Mind adding some? I think you can reuse the val.IsObjxMapSlice() ones
There was a problem hiding this comment.
Due to a previous pull request, this part is no longer necessary. Updated the code and added tests.
|
I agree. What would you consider the case for error though? Not being one of "" or "[]" or "[I]"? |
|
@hanzei any update on the last commit? |
Correct. I would limit |
|
Done |
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