mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
test(util): add more getQuerystring() tests
This commit is contained in:
@ -235,6 +235,28 @@ export function run() {
|
|||||||
describe('getQuerystring', function() {
|
describe('getQuerystring', function() {
|
||||||
it('should have no entries for empty url', () => {
|
it('should have no entries for empty url', () => {
|
||||||
expect(util.getQuerystring('')).toEqual({});
|
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', () => {
|
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', () => {
|
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',
|
key1: '1',
|
||||||
key2: '2'
|
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 &&', () => {
|
it('should ignore empty ?& and &&', () => {
|
||||||
expect(util.getQuerystring('http://localhost:1234/#?&&')).toEqual({});
|
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() {
|
describe('isTrueProperty', function() {
|
||||||
|
@ -182,11 +182,14 @@ export function getQuerystring(url: string): any {
|
|||||||
const startIndex = url.indexOf('?');
|
const startIndex = url.indexOf('?');
|
||||||
if (startIndex !== -1) {
|
if (startIndex !== -1) {
|
||||||
const queries = url.slice(startIndex + 1).split('&');
|
const queries = url.slice(startIndex + 1).split('&');
|
||||||
queries.filter((param) => { return param.indexOf('=') > 0; }).forEach((param) => {
|
for (var i = 0; i < queries.length; i++) {
|
||||||
var split = param.split('=');
|
if (queries[i].indexOf('=') > 0) {
|
||||||
if(split.length > 1)
|
var split = queries[i].split('=');
|
||||||
queryParams[split[0].toLowerCase()] = split[1].split('#')[0];
|
if (split.length > 1) {
|
||||||
});
|
queryParams[split[0].toLowerCase()] = split[1].split('#')[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return queryParams;
|
return queryParams;
|
||||||
|
Reference in New Issue
Block a user