Skip to content

Commit ff927b2

Browse files
watildeitaloacasas
authored andcommittedFeb 25, 2017
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

+23
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+
const qsUnescapeTestCases = [
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+
function errDecode(str) {
314+
throw new Error('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
function demoEncode(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
const prevUnescape = qs.unescape;
313336
qs.unescape = function(str) {

0 commit comments

Comments
 (0)