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>
This commit is contained in:
Brian White authored and Myles Borins committed 2016-04-11 11:10:47 -04:00
1 parent aed22d0855
commit 65fc4e36ce
2 files changed
+11 -1

No files matched your search

+6 -1
View File
@@ -138,7 +138,12 @@ QueryString.escape = function(str) {
}
// Surrogate pair
++i;
c = 0x10000 + (((c & 0x3FF) << 10) | (str.charCodeAt(i) & 0x3FF));
var c2;
if (i < str.length)
c2 = str.charCodeAt(i) & 0x3FF;
else
throw new URIError('URI malformed');
c = 0x10000 + (((c & 0x3FF) << 10) | c2);
out += hexTable[0xF0 | (c >> 18)] +
hexTable[0x80 | ((c >> 12) & 0x3F)] +
hexTable[0x80 | ((c >> 6) & 0x3F)] +
+5
View File
@@ -139,6 +139,11 @@ qsWeirdObjects.forEach(function(testCase) {
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
assert.strictEqual('foo=0', qs.stringify({ foo: 0 }));
assert.strictEqual('foo=0', qs.stringify({ foo: -0 }));