Skip to content

Commit a2ad216

Browse files
mscdexevanlucas
authored andcommitted
querystring: don't stringify bad surrogate pair
Fixes: #3702 PR-URL: #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>
1 parent 4271732 commit a2ad216

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/querystring.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ QueryString.escape = function(str) {
141141
if (i < str.length)
142142
c2 = str.charCodeAt(i) & 0x3FF;
143143
else
144-
c2 = 0;
144+
throw new URIError('URI malformed');
145145
lastPos = i + 1;
146146
c = 0x10000 + (((c & 0x3FF) << 10) | c2);
147147
out += hexTable[0xF0 | (c >> 18)] +

test/parallel/test-querystring.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ qsWeirdObjects.forEach(function(testCase) {
139139
assert.equal(testCase[1], qs.stringify(testCase[0]));
140140
});
141141

142+
// invalid surrogate pair throws URIError
143+
assert.throws(function() {
144+
qs.stringify({ foo: '\udc00' });
145+
}, URIError);
146+
142147
// coerce numbers to string
143148
assert.strictEqual('foo=0', qs.stringify({ foo: 0 }));
144149
assert.strictEqual('foo=0', qs.stringify({ foo: -0 }));

0 commit comments

Comments
 (0)