From 469dd884deb3047ae70dce6fcbbf69154ad491b5 Mon Sep 17 00:00:00 2001 From: Romain Dunand Date: Thu, 31 Mar 2022 20:30:26 +0200 Subject: [PATCH] fix(encodeQueryItem): stringify boolean values (#51) Co-authored-by: Pooya Parsa --- src/query.ts | 2 +- test/query.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/query.ts b/src/query.ts index 4207109..bbcec7f 100644 --- a/src/query.ts +++ b/src/query.ts @@ -35,7 +35,7 @@ export function parseQuery (paramsStr: string = ''): QueryObject { } export function encodeQueryItem (key: string, val: QueryValue): string { - if (typeof val === 'number') { + if (typeof val === 'number' || typeof val === 'boolean') { val = String(val) } if (!val) { diff --git a/test/query.test.ts b/test/query.test.ts index 55cd3c7..e4fecec 100644 --- a/test/query.test.ts +++ b/test/query.test.ts @@ -11,6 +11,7 @@ describe('withQuery', () => { { input: '/?test', query: { foo: 0 }, out: '/?test&foo=0' }, { input: '/?test', query: { foo: 1 }, out: '/?test&foo=1' }, { input: '/?foo=1', query: { foo: 2 }, out: '/?foo=2' }, + { input: '/?foo=1', query: { foo: true, bar: false }, out: '/?foo=true&bar=false' }, { input: '/', query: { email: 'some email.com' },