Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode boolean query parameters as integers #345

Merged
merged 6 commits into from
Nov 6, 2020

Conversation

bakerkretzmar
Copy link
Collaborator

This PR changes how we handle query parameters so that boolean values are encoded as integers in the query string. We do this by passing a custom encoder function to qs.stringify() that casts booleans to numbers (and ignores everything else).

Before

route('messages', {
    collector: 1,
    body: true,
});

// 'http://example.com/collector/1/messages?body=true'

After

route('messages', {
    collector: 1,
    body: true,
});

// 'http://example.com/collector/1/messages?body=1'

Motivation

  1. Parity with Laravel's route() helper, which also encodes booleans as integers in query strings.
  2. Compatibility with Laravel's boolean validation rule, which only recognizes true, false, 0, 1, "0", and "1".

Closes #340.

@bakerkretzmar bakerkretzmar added this to the v1.0 milestone Oct 30, 2020
bakerkretzmar added a commit that referenced this pull request Oct 30, 2020
bakerkretzmar added a commit that referenced this pull request Nov 4, 2020
- Move Usage above Setup
- Remove 'basic setup' section about @routes directive, it's covered in Installation
- Wording fixes
- Add note about boolean encoding (see #345)
- Remove old 'Artisan Command' section
@bakerkretzmar bakerkretzmar merged commit ae2fd97 into develop Nov 6, 2020
@bakerkretzmar bakerkretzmar deleted the jbk/cast-query-bools branch November 6, 2020 18:05
bakerkretzmar added a commit that referenced this pull request Nov 6, 2020
* Add upgrade guide

* Wip

* Wip

* Update GitHub actions to not run on Markdown files

* Wip

* Formatting

* Add changes in #337

* Add anchor links

* Add changes in #338

* Add changes in #341, formatting

* Wip

* Update usage examples in Readme

* Move CSP section down

* LICENSE.md → LICENSE

* Wip

* Wip

* Formatting

* Add new features section to Upgrading

* Prep Changelog headers and tags for v1

* Move current() with query fix to Fixed section

* Add entries for #334 and #344 to Upgrading

* Add Upgrading entry for check() being deprecated

* Add #345 to Upgrading

* Wip on Readme

* JavaScript → Javascript

* Wording/formatting

* Update Readme:
- Move Usage above Setup
- Remove 'basic setup' section about @routes directive, it's covered in Installation
- Wording fixes
- Add note about boolean encoding (see #345)
- Remove old 'Artisan Command' section

* Formatting

* Formatting and wording

* Javascript → JavaScript

* Remove unused heading link

* Add section under 'Other' for setting up an API endpoint to return routes, link to that from SPA and JS sections

* Fix wording re: watching files

* :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant