为什么以下测试失败?
function queryString2Map(queryString) {
var pairs = [], i, keyValuePair, key, value, map = {};
if (queryString !== '') {
pairs = queryString.split('&');
for (i = 0; i < pairs.length; i += 1) {
keyValuePair = pairs[i].split('=');
key = decodeURIComponent(keyValuePair[0]);
value = (keyValuePair.length > 1) ? decodeURIComponent(keyValuePair[1]) : undefined;
map[key] = value;
}
}
return map;
}
test("queryString2Map", 1, function () {
var qs = 'a=123&bob=%20a%20&symbols=%22%24%25%5E%26%3C%3E%2F%5C%3A~%40%3B%23&undef';
var map = {
'a': '123',
'bob': ' a ',
'symbols': '"$%^&<>/\\:~@;#',
'undef': undefined
};
deepEqual(queryString2Map(qs), map, "querystring converted to map");
});
queryString2Map 返回的对象与测试中的地图对象相同,那么为什么测试会失败?