Skip to content

Commit 4e3ea02

Browse files
querystring: Parse multiple separator characters
1 parent 68dc69a commit 4e3ea02

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/querystring.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ QueryString.stringify = QueryString.encode = function(obj, sep, eq, options) {
202202
QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
203203
sep = sep || '&';
204204
eq = eq || '=';
205+
var eqLen = eq.length;
205206
var obj = {};
206207

207208
if (typeof qs !== 'string' || qs.length === 0) {
@@ -235,7 +236,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
235236

236237
if (idx >= 0) {
237238
k = decodeStr(x.substring(0, idx), decode);
238-
v = decodeStr(x.substring(idx + 1), decode);
239+
v = decodeStr(x.substring(idx + eqLen), decode);
239240
} else {
240241
k = decodeStr(x, decode);
241242
v = '';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const assert = require('assert');
3+
const qs = require('querystring');
4+
5+
assert.deepEqual(
6+
qs.parse('foo=>bar&&bar=>baz', '&&', '=>'),
7+
{foo: 'bar', bar: 'baz'}
8+
);
9+
10+
assert.equal(
11+
qs.stringify({foo: 'bar', bar: 'baz'}, '&&', '=>'),
12+
'foo=>bar&&bar=>baz'
13+
);
14+
15+
assert.deepEqual(
16+
qs.parse('foo==>bar, bar==>baz', ', ', '==>'),
17+
{foo: 'bar', bar: 'baz'}
18+
);
19+
20+
assert.equal(
21+
qs.stringify({foo: 'bar', bar: 'baz'}, ', ', '==>'),
22+
'foo==>bar, bar==>baz'
23+
);

0 commit comments

Comments
 (0)