Skip to content

Commit

Permalink
[Robustness] stringify: avoid relying on a global undefined (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha authored and ljharb committed Dec 27, 2021
1 parent 4a17709 commit 02ca358
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var stringify = function stringify(
var objKeys;
if (generateArrayPrefix === 'comma' && isArray(obj)) {
// we need to join elements in
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : undefined }];
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
} else if (isArray(filter)) {
objKeys = filter;
} else {
Expand All @@ -128,7 +128,7 @@ var stringify = function stringify(

for (var j = 0; j < objKeys.length; ++j) {
var key = objKeys[j];
var value = typeof key === 'object' && key.value !== undefined ? key.value : obj[key];
var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];

if (skipNulls && value === null) {
continue;
Expand Down Expand Up @@ -164,7 +164,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
return defaults;
}

if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
throw new TypeError('Encoder has to be a function.');
}

Expand Down

0 comments on commit 02ca358

Please sign in to comment.