From a764b090136f1c9994b9c6f8b34b577af6460ef2 Mon Sep 17 00:00:00 2001 From: "mohamed.gad" Date: Mon, 15 Jun 2020 01:34:14 +0200 Subject: [PATCH 1/3] fix(query): Fix query props should be casted into string (fix #2131) --- src/util/query.js | 2 +- test/unit/specs/query.spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util/query.js b/src/util/query.js index b9abc211f..029fbd772 100644 --- a/src/util/query.js +++ b/src/util/query.js @@ -29,7 +29,7 @@ export function resolveQuery ( parsedQuery = {} } for (const key in extraQuery) { - parsedQuery[key] = extraQuery[key] + parsedQuery[key] = extraQuery[key].toString() } return parsedQuery } diff --git a/test/unit/specs/query.spec.js b/test/unit/specs/query.spec.js index 22c1e6c74..1b8a18e6e 100644 --- a/test/unit/specs/query.spec.js +++ b/test/unit/specs/query.spec.js @@ -19,6 +19,11 @@ describe('Query utils', () => { arr: ['1', null, '2'] }) }) + + it('should cast query props into string', () => { + const query = resolveQuery('foo=bar&foo=k', { baz: 1 }) + expect(typeof query.baz).toBe('string') + }) }) describe('stringifyQuery', () => { From d987cc0f8e4feaf8409661031eaaeba83173d7ea Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 18 Jun 2020 15:48:24 +0200 Subject: [PATCH 2/3] Apply suggestions from code review --- src/util/query.js | 3 ++- test/unit/specs/query.spec.js | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/util/query.js b/src/util/query.js index 029fbd772..b2c5286a5 100644 --- a/src/util/query.js +++ b/src/util/query.js @@ -29,7 +29,8 @@ export function resolveQuery ( parsedQuery = {} } for (const key in extraQuery) { - parsedQuery[key] = extraQuery[key].toString() + const value = extraQuery[key] + parsedQuery[key] = Array.isArray(value) ? value.map(v => '' + v) : '' + value } return parsedQuery } diff --git a/test/unit/specs/query.spec.js b/test/unit/specs/query.spec.js index 1b8a18e6e..f825ab96e 100644 --- a/test/unit/specs/query.spec.js +++ b/test/unit/specs/query.spec.js @@ -20,9 +20,14 @@ describe('Query utils', () => { }) }) - it('should cast query props into string', () => { + it('should cast query values into string', () => { const query = resolveQuery('foo=bar&foo=k', { baz: 1 }) - expect(typeof query.baz).toBe('string') + expect(query.baz).toBe('1') + }) + + it('should cast query array values into string', () => { + const query = resolveQuery('foo=bar&foo=k', { baz: [1, '2'] }) + expect(query.baz).toEqual(['1', '2']) }) }) From 39a8a2565b2656dad50aa30c7d241d7c66cdf99e Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 18 Jun 2020 15:53:06 +0200 Subject: [PATCH 3/3] Update test/unit/specs/query.spec.js --- test/unit/specs/query.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/specs/query.spec.js b/test/unit/specs/query.spec.js index f825ab96e..58060ff2c 100644 --- a/test/unit/specs/query.spec.js +++ b/test/unit/specs/query.spec.js @@ -24,7 +24,6 @@ describe('Query utils', () => { const query = resolveQuery('foo=bar&foo=k', { baz: 1 }) expect(query.baz).toBe('1') }) - it('should cast query array values into string', () => { const query = resolveQuery('foo=bar&foo=k', { baz: [1, '2'] }) expect(query.baz).toEqual(['1', '2'])