mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
Differentiate between flags and empty keys in $location.hashSearch
* #foo?key=var&flag&emptyKey= should parse into
{key:'val', flag: true, emptyKey: ''}
* added docs and spec for parseKeyValue function
This commit is contained in:
@@ -79,5 +79,17 @@ describe('equals', function(){
|
||||
expect(equals({name:'misko'}, {name:'misko', $id:2})).toEqual(true);
|
||||
expect(equals({name:'misko', $id:1}, {name:'misko'})).toEqual(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('parseKeyValue', function() {
|
||||
it('should parse a string into key-value pairs', function() {
|
||||
expect(parseKeyValue('')).toEqual({});
|
||||
expect(parseKeyValue('simple=pair')).toEqual({simple: 'pair'});
|
||||
expect(parseKeyValue('first=1&second=2')).toEqual({first: '1', second: '2'});
|
||||
expect(parseKeyValue('escaped%20key=escaped%20value')).
|
||||
toEqual({'escaped key': 'escaped value'});
|
||||
expect(parseKeyValue('emptyKey=')).toEqual({emptyKey: ''});
|
||||
expect(parseKeyValue('flag1&key=value&flag2')).
|
||||
toEqual({flag1: true, key: 'value', flag2: true});
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user