From 96f4d93e171ada73cb466a5abe3ac23c9ed4217a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 22 Aug 2024 10:53:38 -0700 Subject: [PATCH] [Fix] `stringify`: avoid a crash when a `filter` key is `null` --- lib/stringify.js | 2 +- test/stringify.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stringify.js b/lib/stringify.js index 3bdd4e93..2666eaf9 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -162,7 +162,7 @@ var stringify = function stringify( for (var j = 0; j < objKeys.length; ++j) { var key = objKeys[j]; - var value = typeof key === 'object' && typeof key.value !== 'undefined' + var value = typeof key === 'object' && key && typeof key.value !== 'undefined' ? key.value : obj[key]; diff --git a/test/stringify.js b/test/stringify.js index be9186d6..75eaf738 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -1298,7 +1298,7 @@ test('stringifies empty keys', function (t) { t.test('stringifies non-string keys', function (st) { var actual = qs.stringify({ a: 'b', 'false': {} }, { - filter: ['a', false], + filter: ['a', false, null], allowDots: true, encodeDotInKeys: true });