diff --git a/lib/querystring.js b/lib/querystring.js index 8735d2814bc307..40677ffb0f0859 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -202,6 +202,7 @@ QueryString.stringify = QueryString.encode = function(obj, sep, eq, options) { QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { sep = sep || '&'; eq = eq || '='; + const eqLen = eq.length; var obj = {}; if (typeof qs !== 'string' || qs.length === 0) { @@ -235,7 +236,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { if (idx >= 0) { k = decodeStr(x.substring(0, idx), decode); - v = decodeStr(x.substring(idx + 1), decode); + v = decodeStr(x.substring(idx + eqLen), decode); } else { k = decodeStr(x, decode); v = ''; diff --git a/test/parallel/test-querystring-multichar-separator.js b/test/parallel/test-querystring-multichar-separator.js new file mode 100644 index 00000000000000..257492659bdfde --- /dev/null +++ b/test/parallel/test-querystring-multichar-separator.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const qs = require('querystring'); + +assert.deepEqual( + qs.parse('foo=>bar&&bar=>baz', '&&', '=>'), + {foo: 'bar', bar: 'baz'} +); + +assert.strictEqual( + qs.stringify({foo: 'bar', bar: 'baz'}, '&&', '=>'), + 'foo=>bar&&bar=>baz' +); + +assert.deepEqual( + qs.parse('foo==>bar, bar==>baz', ', ', '==>'), + {foo: 'bar', bar: 'baz'} +); + +assert.strictEqual( + qs.stringify({foo: 'bar', bar: 'baz'}, ', ', '==>'), + 'foo==>bar, bar==>baz' +);