Skip to content

Commit ff927b2

Browse files
watildeItalo A. Casas
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 ea29d48 commit ff927b2

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
@@ -105,6 +105,17 @@ const qsNoMungeTestCases = [
105105
['trololol=yes&lololo=no',{'trololol': 'yes','lololo': 'no'}]
106106
];
107107

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

@@ -298,6 +309,12 @@ function demoDecode(str){
298309
check(qs.parse('a=a&b=b&c=c',null,null,{decodeURIComponent: demoDecode}),
299310
{aa: 'aa',bb: 'bb',cc: 'cc'});
300311

312+
// Test QueryString.unescape
313+
functionerrDecode(str){
314+
thrownewError('To jump to the catch scope');
315+
}
316+
check(qs.parse('a=a',null,null,{decodeURIComponent: errDecode}),
317+
{a: 'a'});
301318

302319
// Test custom encode
303320
functiondemoEncode(str){
@@ -308,6 +325,12 @@ assert.strictEqual(
308325
qs.stringify(obj,null,null,{encodeURIComponent: demoEncode}),
309326
'a=a&b=b&c=c');
310327

328+
// Test QueryString.unescapeBuffer
329+
qsUnescapeTestCases.forEach(function(testCase){
330+
assert.strictEqual(qs.unescape(testCase[0]),testCase[1]);
331+
assert.strictEqual(qs.unescapeBuffer(testCase[0]).toString(),testCase[1]);
332+
});
333+
311334
// test overriding .unescape
312335
constprevUnescape=qs.unescape;
313336
qs.unescape=function(str){

0 commit comments

Comments
(0)