Skip to content
Prev Previous commit
Next Next commit
if array contains __proto__
if array contains __proto__, use Object.create(null)
  • Loading branch information
JungMinu committed Nov 12, 2015
commit c7de80b40213cded9dae0e33ad785366ec169e0b
16 changes: 9 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,17 @@ function arrayToHash(array) {

var hash;

if (array.indexOf('__proto__') > -1)
{
hash = Object.create(null);
}else{
hash = {};
}

array.forEach(function(val, idx) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if idx is not used, why pass it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YuriSolovyov Hmm, It was there before I made a PR,
I speculate that it could be used

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not used anywhere in the scope of the function, IMO it is safe to drop it


if(val==='__proto__'){
hash = Object.create(null);
}else{
hash = {};
}


hash[val] = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd check if val was __proto__ here and discard it if it was, I think. cc @bnoordhuis


});

return hash;
Expand Down