Properly handle boolean flags in HTTP querystrings #428
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.
Description
HTTP querystrings do not define how boolean values should be encoded, how they are handled depend on the API parsing the querystring.
Kuzzle's convention is that, for booleans, option values are irrelevant. Instead, a boolean option is truthy if it' set in the querystring, and falsey otherwise.
So this:
url?foo=0
orurl?foo=false
makes Kuzzle interpret thefoo
option as a non-empty string, and thus as "true" when converted to a boolean.This PR fixes how the SDK passes boolean options to the querystring, only setting one if it's truthy, and skipping it if it's not.
How to test it
Use Kuzzle's CLI
createFirstAdmin
command: even if you tell it to not reset anonymous rights, it resets it because of that bug. If you apply these changes, the CLI acts as expected.Other changes
Add a missing unit test about how arrays are encoded in the querystring.