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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Basic implementation and test
  • Loading branch information
bakerkretzmar committed Oct 28, 2020
commit c1c852edd91d6b5e2d909c90e564cee6feefab14
5 changes: 5 additions & 0 deletions src/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class Router extends String {
arrayFormat: 'indices',
encodeValuesOnly: true,
skipNulls: true,
encoder: (value, encoder) => {
return typeof value === 'boolean'
? String(Number(value))
: encoder(value);
},
});
}

Expand Down
4 changes: 4 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ describe('route()', () => {
same(route('posts.index', { filled: 'filling', empty: null }), 'https://ziggy.dev/posts?filled=filling');
});

test('can cast boolean query parameters to integers', () => {
same(route('posts.show', { post: 1, preview: true }), 'https://ziggy.dev/posts/1?preview=1');
});

test('can explicitly append query parameters using _query parameter', () => {
same(
route('events.venues.show', {
Expand Down