Browse Source

querystring: don't stringify bad surrogate pair

Fixes: https://github.com/nodejs/node/issues/3702
PR-URL: https://github.com/nodejs/node/pull/5858
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
process-exit-stdio-flushing
Brian White 9 years ago
parent
commit
c169ac6bab
  1. 2
      lib/querystring.js
  2. 5
      test/parallel/test-querystring.js

2
lib/querystring.js

@ -141,7 +141,7 @@ QueryString.escape = function(str) {
if (i < str.length) if (i < str.length)
c2 = str.charCodeAt(i) & 0x3FF; c2 = str.charCodeAt(i) & 0x3FF;
else else
c2 = 0; throw new URIError('URI malformed');
lastPos = i + 1; lastPos = i + 1;
c = 0x10000 + (((c & 0x3FF) << 10) | c2); c = 0x10000 + (((c & 0x3FF) << 10) | c2);
out += hexTable[0xF0 | (c >> 18)] + out += hexTable[0xF0 | (c >> 18)] +

5
test/parallel/test-querystring.js

@ -139,6 +139,11 @@ qsWeirdObjects.forEach(function(testCase) {
assert.equal(testCase[1], qs.stringify(testCase[0])); assert.equal(testCase[1], qs.stringify(testCase[0]));
}); });
// invalid surrogate pair throws URIError
assert.throws(function() {
qs.stringify({ foo: '\udc00' });
}, URIError);
// coerce numbers to string // coerce numbers to string
assert.strictEqual('foo=0', qs.stringify({ foo: 0 })); assert.strictEqual('foo=0', qs.stringify({ foo: 0 }));
assert.strictEqual('foo=0', qs.stringify({ foo: -0 })); assert.strictEqual('foo=0', qs.stringify({ foo: -0 }));

Loading…
Cancel
Save