From f6ae63e4dedc06898e94c1554b7fe3c8b1612817 Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Fri, 13 Nov 2020 07:11:00 +0530 Subject: [PATCH] lib: add support for bigint in querystring Add support for bigint in strgify for querystring method. This use the same method as the number but escapes the exponential notation method as bigint does not play well with the numbers. Instead in case of stringification there is a separate condition clause to filter out bigint. Fixes: #36080 --- lib/querystring.js | 5 ++++- test/parallel/test-querystring.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/querystring.js b/lib/querystring.js index 0aa798d462b25c..310166bb4f91d4 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -158,7 +158,8 @@ function qsEscape(str) { function stringifyPrimitive(v) { if (typeof v === 'string') return v; - if (typeof v === 'number' && NumberIsFinite(v)) + if ((typeof v === 'number' && NumberIsFinite(v)) || + (typeof v === 'bigint')) return '' + v; if (typeof v === 'boolean') return v ? 'true' : 'false'; @@ -174,6 +175,8 @@ function encodeStringified(v, encode) { // escaping due to the inclusion of a '+' in the output return (MathAbs(v) < 1e21 ? '' + v : encode('' + v)); } + if (typeof v === 'bigint') + return '' + v; if (typeof v === 'boolean') return v ? 'true' : 'false'; return ''; diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 58554f0d85c438..bb0f257b4be308 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -44,6 +44,9 @@ const qsTestCases = [ ['__defineGetter__=asdf', '__defineGetter__=asdf', JSON.parse('{"__defineGetter__":"asdf"}')], + ['foo=12345678901234567', + 'foo=12345678901234567', + { 'foo': 12345678901234567n }], ['foo=918854443121279438895193', 'foo=918854443121279438895193', { 'foo': '918854443121279438895193' }],