Skip to content

Commit 6a66867

Browse files
committed
add decodeURIComponent
1 parent f11f0d0 commit 6a66867

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"scripts": {
1212
"start": "yarn test -- --watchAll",
1313
"test": "cross-env NODE_ENV=development jest",
14+
"gzip": "gzip -c dist/tiny-querystring.min.js | wc -c",
1415
"rm": "rimraf dist",
1516
"mkdir": "mkdirp dist",
1617
"prebuild": "run-s rm mkdir",

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ describe('parse', () => {
4444
test('a=b&=&e=f&a=c&a+=d+dd', () => {
4545
expect(parse('a=b&=&e=f&a=c&a+=d+dd')).toEqual({ a: ['b', 'c'], 'a ': 'd dd', e: 'f', '': '' });
4646
});
47+
48+
test('url=http%3A%2F%2Fcap32.com%2Fquery%3Fa%3D2%26b%3D1', () => {
49+
expect(parse('url=http%3A%2F%2Fcap32.com%2Fquery%3Fa%3D2%26b%3D1')).toEqual({ url: 'http://cap32.com/query?a=2&b=1' });
50+
});
4751
});
4852

4953
describe('stringify', () => {

tiny-querystring.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ exports.parse = function parse(str) {
99
.reduce(function (obj, item, index) {
1010
var ref = item.split('=');
1111
var key = ref[0] || '';
12-
var val = ref[1] || '';
12+
var val = decodeURIComponent(ref[1] || '');
1313
var prev = obj[key];
14-
obj[key] = typeof prev === 'undefined' ? val : [].concat(prev, val);
14+
obj[key] = prev === undefined ? val : [].concat(prev, val);
1515
return obj;
1616
}, {})
1717
;

0 commit comments

Comments
 (0)