diff --git a/ionic/util/test/util.spec.ts b/ionic/util/test/util.spec.ts index d08463fe1e..92081e788a 100644 --- a/ionic/util/test/util.spec.ts +++ b/ionic/util/test/util.spec.ts @@ -235,6 +235,28 @@ export function run() { describe('getQuerystring', function() { it('should have no entries for empty url', () => { expect(util.getQuerystring('')).toEqual({}); + expect(util.getQuerystring(null)).toEqual({}); + expect(util.getQuerystring(undefined)).toEqual({}); + }); + + it('should have no entries when without ?', () => { + expect(util.getQuerystring('http://localhost:1234/')).toEqual({}); + }); + + it('should have no entries with only ?', () => { + expect(util.getQuerystring('http://localhost:1234/?')).toEqual({}); + }); + + it('should have no entries for key with no =', () => { + expect(util.getQuerystring('http://localhost:1234/?key')).toEqual({}); + }); + + it('should have no entries with only #?', () => { + expect(util.getQuerystring('http://localhost:1234/#?')).toEqual({}); + }); + + it('should have no entries with only #?=', () => { + expect(util.getQuerystring('http://localhost:1234/#?=')).toEqual({}); }); it('should have no entries for url with no "?" character', () => { @@ -242,12 +264,25 @@ export function run() { }); 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({ + expect(util.getQuerystring('http://localhost:1234/#key1=1&key2x=2x?key3=3&key4=4')).toEqual({ + key3: '3', + key4: '4' + }); + }); + + it('should lowercase param keys', () => { + expect(util.getQuerystring('http://localhost:1234/#?KEY1=1&kEy2=2')).toEqual({ key1: '1', key2: '2' }); }); + it('should not include any values when # comes after ?', () => { + expect(util.getQuerystring('http://localhost:1234/?key1=1#key2=2')).toEqual({ + key1: '1' + }); + }); + it('should ignore empty ?& and &&', () => { expect(util.getQuerystring('http://localhost:1234/#?&&')).toEqual({}); @@ -257,6 +292,12 @@ export function run() { }); }); + it('should get "" when key has no value', () => { + expect(util.getQuerystring('http://localhost:1234/#?key=')).toEqual({ + key: '' + }); + }); + }); describe('isTrueProperty', function() { diff --git a/ionic/util/util.ts b/ionic/util/util.ts index 38ed925d59..44c1efc0fb 100644 --- a/ionic/util/util.ts +++ b/ionic/util/util.ts @@ -182,11 +182,14 @@ export function getQuerystring(url: string): any { const startIndex = url.indexOf('?'); if (startIndex !== -1) { const queries = url.slice(startIndex + 1).split('&'); - queries.filter((param) => { return param.indexOf('=') > 0; }).forEach((param) => { - var split = param.split('='); - if(split.length > 1) - queryParams[split[0].toLowerCase()] = split[1].split('#')[0]; - }); + for (var i = 0; i < queries.length; i++) { + if (queries[i].indexOf('=') > 0) { + var split = queries[i].split('='); + if (split.length > 1) { + queryParams[split[0].toLowerCase()] = split[1].split('#')[0]; + } + } + } } } return queryParams;