Skip to content

Commit fb34d9c

Browse files
DavidCai1111italoacasas
authored andcommitted
test: increase querystring coverage
PR-URL: #12163 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent d6e9cf7 commit fb34d9c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/parallel/test-querystring-escape.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ assert.deepStrictEqual(qs.escape('test'), 'test');
99
assert.deepStrictEqual(qs.escape({}), '%5Bobject%20Object%5D');
1010
assert.deepStrictEqual(qs.escape([5, 10]), '5%2C10');
1111
assert.deepStrictEqual(qs.escape('Ŋōđĕ'), '%C5%8A%C5%8D%C4%91%C4%95');
12+
assert.deepStrictEqual(qs.escape('testŊōđĕ'), 'test%C5%8A%C5%8D%C4%91%C4%95');
13+
assert.deepStrictEqual(qs.escape(`${String.fromCharCode(0xD800 + 1)}test`),
14+
'%F0%90%91%B4est');
15+
assert.throws(() => qs.escape(String.fromCharCode(0xD800 + 1)),
16+
/^URIError: URI malformed$/);
1217

1318
// using toString for objects
1419
assert.strictEqual(
@@ -17,9 +22,11 @@ assert.strictEqual(
1722
);
1823

1924
// toString is not callable, must throw an error
20-
assert.throws(() => qs.escape({toString: 5}));
25+
assert.throws(() => qs.escape({toString: 5}),
26+
/^TypeError: Cannot convert object to primitive value$/);
2127

2228
// should use valueOf instead of non-callable toString
2329
assert.strictEqual(qs.escape({toString: 5, valueOf: () => 'test'}), 'test');
2430

25-
assert.throws(() => qs.escape(Symbol('test')));
31+
assert.throws(() => qs.escape(Symbol('test')),
32+
/^TypeError: Cannot convert a Symbol value to a string$/);

test/parallel/test-querystring.js

+2
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ function demoDecode(str) {
308308
}
309309
check(qs.parse('a=a&b=b&c=c', null, null, { decodeURIComponent: demoDecode }),
310310
{ aa: 'aa', bb: 'bb', cc: 'cc' });
311+
check(qs.parse('a=a&b=b&c=c', null, '==', { decodeURIComponent: (str) => str }),
312+
{ 'a=a': '', 'b=b': '', 'c=c': '' });
311313

312314
// Test QueryString.unescape
313315
function errDecode(str) {

0 commit comments

Comments
 (0)