From 4056af664f149a66e40af1576937d038ccc2dc96 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Mon, 3 May 2021 23:01:43 +0800 Subject: [PATCH] test: complete coverage of querystring PR-URL: https://github.com/nodejs/node/pull/38520 Refs: https://coverage.nodejs.org/coverage-68e6673224365120/lib/querystring.js.html#L179 Reviewed-By: Rich Trott Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Zijian Liu Reviewed-By: Darshan Sen --- test/parallel/test-querystring.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 7a001f6a029c42..de45ef165874b2 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -307,6 +307,7 @@ assert.strictEqual(qs.stringify({ foo: -0 }), 'foo=0'); assert.strictEqual(qs.stringify({ foo: 3 }), 'foo=3'); assert.strictEqual(qs.stringify({ foo: -72.42 }), 'foo=-72.42'); assert.strictEqual(qs.stringify({ foo: NaN }), 'foo='); +assert.strictEqual(qs.stringify({ foo: 1e21 }), 'foo=1e%2B21'); assert.strictEqual(qs.stringify({ foo: Infinity }), 'foo='); // nested @@ -450,6 +451,14 @@ check(qs.parse('%\u0100=%\u0101'), { '%Ā': '%ā' }); 'a=a&b=b&c=c'); } +// Test custom encode for different types +{ + const obj = { number: 1, bigint: 2n, true: true, false: false, object: {} }; + assert.strictEqual( + qs.stringify(obj, null, null, { encodeURIComponent: (v) => v }), + 'number=1&bigint=2&true=true&false=false&object='); +} + // Test QueryString.unescapeBuffer qsUnescapeTestCases.forEach((testCase) => { assert.strictEqual(qs.unescape(testCase[0]), testCase[1]);