Skip to content

Commit 667c9e9

Browse files
authoredFeb 9, 2021
Ignore ending ampersand when parsing (#306)
1 parent 39aef91 commit 667c9e9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
 

‎index.js

+4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ function parse(query, options) {
244244
}
245245

246246
for (const param of query.split('&')) {
247+
if (param === '') {
248+
continue;
249+
}
250+
247251
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
248252

249253
// Missing `=` should be `null`:

‎test/parse.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ test('query strings starting with a `&`', t => {
1313
t.deepEqual(queryString.parse('&foo=bar&foo=baz'), {foo: ['bar', 'baz']});
1414
});
1515

16+
test('query strings ending with a `&`', t => {
17+
t.deepEqual(queryString.parse('foo=bar&'), {foo: 'bar'});
18+
t.deepEqual(queryString.parse('foo=bar&&&'), {foo: 'bar'});
19+
});
20+
1621
test('parse a query string', t => {
1722
t.deepEqual(queryString.parse('foo=bar'), {foo: 'bar'});
1823
});

0 commit comments

Comments
 (0)
Please sign in to comment.