From 816c4d2340c257b473be6528a017ebfaaf22a2ca Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 31 Jan 2018 09:56:22 +0100 Subject: [PATCH] url: fix for boolean querystring parameters Without this fix then the querystring looks like ?abool=true which causes a mismatch with the angular routing. This results in a redirect and messes up the browser history and back button. --- public/app/core/utils/url.ts | 6 +++++- public/app/stores/ViewStore/ViewStore.jest.ts | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/public/app/core/utils/url.ts b/public/app/core/utils/url.ts index 0b629768b92..b57d5721d57 100644 --- a/public/app/core/utils/url.ts +++ b/public/app/core/utils/url.ts @@ -12,7 +12,11 @@ export function toUrlParams(a) { let add = function(k, v) { v = typeof v === 'function' ? v() : v === null ? '' : v === undefined ? '' : v; - s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v); + if (typeof v !== 'boolean') { + s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v); + } else { + s[s.length] = encodeURIComponent(k); + } }; let buildParams = function(prefix, obj) { diff --git a/public/app/stores/ViewStore/ViewStore.jest.ts b/public/app/stores/ViewStore/ViewStore.jest.ts index 732f6a81038..b8faed8c0d7 100644 --- a/public/app/stores/ViewStore/ViewStore.jest.ts +++ b/public/app/stores/ViewStore/ViewStore.jest.ts @@ -23,4 +23,10 @@ describe('ViewStore', () => { expect(toJS(store.query.get('values'))).toMatchObject(['A', 'B']); expect(store.currentUrl).toBe('/hello?values=A&values=B'); }); + + it('Query can contain boolean', () => { + store.updatePathAndQuery('/hello', { abool: true }); + expect(toJS(store.query.get('abool'))).toBe(true); + expect(store.currentUrl).toBe('/hello?abool'); + }); });