Skip to content

Commit

Permalink
lib: add support for bigint in querystring
Browse files Browse the repository at this point in the history
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: nodejs#36080
  • Loading branch information
yashLadha committed Nov 13, 2020
1 parent f03f7cb commit f6ae63e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 '';
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
Expand Down

0 comments on commit f6ae63e

Please sign in to comment.