diff --git a/index.js b/index.js index 559ecd47..39e86e3d 100644 --- a/index.js +++ b/index.js @@ -244,6 +244,10 @@ function parse(query, options) { } for (const param of query.split('&')) { + if (param === '') { + continue; + } + let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '='); // Missing `=` should be `null`: diff --git a/test/parse.js b/test/parse.js index 365eb2f7..9bfc0344 100644 --- a/test/parse.js +++ b/test/parse.js @@ -13,6 +13,11 @@ test('query strings starting with a `&`', t => { t.deepEqual(queryString.parse('&foo=bar&foo=baz'), {foo: ['bar', 'baz']}); }); +test('query strings ending with a `&`', t => { + t.deepEqual(queryString.parse('foo=bar&'), {foo: 'bar'}); + t.deepEqual(queryString.parse('foo=bar&&&'), {foo: 'bar'}); +}); + test('parse a query string', t => { t.deepEqual(queryString.parse('foo=bar'), {foo: 'bar'}); });