Skip to content

Commit f8884dd

Browse files
watildeMylesBorins
authored andcommitted
test: add cases for unescape & unescapeBuffer
These two functions in the querystring are used as a fallback. To test them, two test cases were added which make errors that will be caught. PR-URL: #11326 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 9a684a1 commit f8884dd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/parallel/test-querystring.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ var qsNoMungeTestCases = [
101101
['trololol=yes&lololo=no', {'trololol': 'yes', 'lololo': 'no'}]
102102
];
103103

104+
const qsUnescapeTestCases = [
105+
['there is nothing to unescape here',
106+
'there is nothing to unescape here'],
107+
['there%20are%20several%20spaces%20that%20need%20to%20be%20unescaped',
108+
'there are several spaces that need to be unescaped'],
109+
['there%2Qare%0-fake%escaped values in%%%%this%9Hstring',
110+
'there%2Qare%0-fake%escaped values in%%%%this%9Hstring'],
111+
['%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2F%30%31%32%33%34%35%36%37',
112+
' !"#$%&\'()*+,-./01234567']
113+
];
114+
104115
assert.strictEqual('918854443121279438895193',
105116
qs.parse('id=918854443121279438895193').id);
106117

@@ -275,6 +286,12 @@ function demoDecode(str) {
275286
check(qs.parse('a=a&b=b&c=c', null, null, { decodeURIComponent: demoDecode }),
276287
{ aa: 'aa', bb: 'bb', cc: 'cc' });
277288

289+
// Test QueryString.unescape
290+
function errDecode(str) {
291+
throw new Error('To jump to the catch scope');
292+
}
293+
check(qs.parse('a=a', null, null, { decodeURIComponent: errDecode }),
294+
{ a: 'a' });
278295

279296
// Test custom encode
280297
function demoEncode(str) {
@@ -285,6 +302,12 @@ assert.equal(
285302
qs.stringify(obj, null, null, { encodeURIComponent: demoEncode }),
286303
'a=a&b=b&c=c');
287304

305+
// Test QueryString.unescapeBuffer
306+
qsUnescapeTestCases.forEach(function(testCase) {
307+
assert.strictEqual(qs.unescape(testCase[0]), testCase[1]);
308+
assert.strictEqual(qs.unescapeBuffer(testCase[0]).toString(), testCase[1]);
309+
});
310+
288311
// test overriding .unescape
289312
var prevUnescape = qs.unescape;
290313
qs.unescape = function(str) {

0 commit comments

Comments
 (0)