From 908ea8cd845b4dc95f7e6ba58ddfa88cb98f413c Mon Sep 17 00:00:00 2001 From: Szymon Stasik Date: Tue, 23 Feb 2016 00:26:06 +0100 Subject: [PATCH 1/2] fix(util): ignore empty query param in getQueryString --- ionic/util/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ionic/util/util.ts b/ionic/util/util.ts index 381608894f..c9613d5cc3 100644 --- a/ionic/util/util.ts +++ b/ionic/util/util.ts @@ -163,7 +163,7 @@ export function getQuerystring(url: string): any { const startIndex = url.indexOf('?'); if (startIndex !== -1) { const queries = url.slice(startIndex + 1).split('&'); - queries.forEach((param) => { + queries.filter((param) => { return param.indexOf('=') > 0; }).forEach((param) => { var split = param.split('='); queryParams[split[0].toLowerCase()] = split[1].split('#')[0]; }); From f8e38efacb4b814b032958fe413fb6673da5a7d4 Mon Sep 17 00:00:00 2001 From: Szymon Stasik Date: Tue, 23 Feb 2016 17:03:19 +0100 Subject: [PATCH 2/2] fix(util): getQueryString tests --- ionic/util/test/util.spec.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ionic/util/test/util.spec.ts b/ionic/util/test/util.spec.ts index 040fad43df..a2b046a5e5 100644 --- a/ionic/util/test/util.spec.ts +++ b/ionic/util/test/util.spec.ts @@ -3,6 +3,32 @@ import * as util from 'ionic-angular/util'; export function run() { describe('extend', function() { + describe('getQuerystring', function() { + it('should have no entries for empty url', () => { + expect(util.getQuerystring('')).toEqual({}); + }); + + it('should have no entries for url with no "?" character', () => { + expect(util.getQuerystring('http://localhost:1234/#key1=1&key2=2')).toEqual({}); + }); + + it('should contain key/value entries for all the parameters after "?" character', () => { + expect(util.getQuerystring('http://localhost:1234/#key0=0&key0x=0x?key1=1&key2=2')).toEqual({ + key1: '1', + key2: '2' + }); + }); + + it('should ignore empty ?& and &&', () => { + expect(util.getQuerystring('http://localhost:1234/#?&&')).toEqual({}); + + expect(util.getQuerystring('http://localhost:1234/#?&&key1=1&key2=2&&')).toEqual({ + key1: '1', + key2: '2' + }); + }); + }); + describe('isTrueProperty', function() { it('should be true from boolean true', () => {