Change multiple values to use array format #10
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the object to be encoded contains an array, the resulting string simply repeats the key for each of the values.
Example:
Results in:
However, this only gives access to one of the values (typically the last one). I came across this issue when trying to use oauth to generate a OAuth URL for the GitHub API.
The solution was to use the array convention to represent multiple values for the same key.
Example:
I don't know if you want to adopt this convention (as it can potentially break existing implementations), but in any case I've included the change in the PR.
EDIT (25 July): It doesn't make sense to just change the convention for everyone that's already using the package, so I've added an optional parameter to
encode()
that activates the array convention. It defaults tofalse
, so everything should work exactly as is if the parameter isn't activated.To activate it,
arrayMode
must be set totrue
. Because of the existing optional parameters in the function, it's necessary to actively set them toundefined
in the function call — unfortunate, but in my opinion still better than not having this option at all.Example: