From e8091ed266ae889dca5f970d193c157d5310740c Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 12 Nov 2015 22:04:29 +0900 Subject: [PATCH 1/9] util: use Object.create(null) for dictionary object Fixes https://github.com/nodejs/node/issues/3788 `arrayToHash()` needs to use `Object.create(null)` for its dictionary object. --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 4eb7a4a0962bc6..18e1dbe49703f8 100644 --- a/lib/util.js +++ b/lib/util.js @@ -159,7 +159,7 @@ function stylizeNoColor(str, styleType) { function arrayToHash(array) { - var hash = {}; + var hash = Object.create(null); array.forEach(function(val, idx) { hash[val] = true; From 54285cad204ff29662f807f7ae28acf127dfc207 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 12 Nov 2015 23:43:36 +0900 Subject: [PATCH 2/9] add if val is `__proto__` add if val is `__proto__`, use `Object.create(null);` --- lib/util.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 18e1dbe49703f8..168de43c955939 100644 --- a/lib/util.js +++ b/lib/util.js @@ -159,9 +159,17 @@ function stylizeNoColor(str, styleType) { function arrayToHash(array) { - var hash = Object.create(null); + + var hash; array.forEach(function(val, idx) { + + if(val==='__proto__'){ + hash = Object.create(null); + }else{ + hash = {}; + } + hash[val] = true; }); From c7de80b40213cded9dae0e33ad785366ec169e0b Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Fri, 13 Nov 2015 00:14:10 +0900 Subject: [PATCH 3/9] if array contains __proto__ if array contains __proto__, use Object.create(null) --- lib/util.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/util.js b/lib/util.js index 168de43c955939..b1ffcf62bbb083 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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) { - - if(val==='__proto__'){ - hash = Object.create(null); - }else{ - hash = {}; - } - + hash[val] = true; + }); return hash; From c61e8c2f069c81ef616052952eaed8d2cf8bc14c Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Fri, 13 Nov 2015 00:18:40 +0900 Subject: [PATCH 4/9] Beautify codes Beautify codes --- lib/util.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/util.js b/lib/util.js index b1ffcf62bbb083..7966708bb30fc3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -162,17 +162,14 @@ function arrayToHash(array) { var hash; - if (array.indexOf('__proto__') > -1) - { + if (array.indexOf('__proto__') > -1) { hash = Object.create(null); - }else{ + } else { hash = {}; } array.forEach(function(val, idx) { - hash[val] = true; - }); return hash; From 36ee9fefd29320ae74754ec44f8bdb26023564ac Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Fri, 13 Nov 2015 00:35:01 +0900 Subject: [PATCH 5/9] remove unused index --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 7966708bb30fc3..5e4c59af21c167 100644 --- a/lib/util.js +++ b/lib/util.js @@ -168,7 +168,7 @@ function arrayToHash(array) { hash = {}; } - array.forEach(function(val, idx) { + array.forEach(function(val) { hash[val] = true; }); From 7fa52db025efffccbcf2e934f691511672855281 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Fri, 13 Nov 2015 00:40:57 +0900 Subject: [PATCH 6/9] remove spaces --- lib/util.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 5e4c59af21c167..cf4a65a96750c5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -159,7 +159,6 @@ function stylizeNoColor(str, styleType) { function arrayToHash(array) { - var hash; if (array.indexOf('__proto__') > -1) { From e412b4f4ca622a30508381c12c2857e4fc655eaf Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Fri, 13 Nov 2015 01:47:40 +0900 Subject: [PATCH 7/9] util: use Object.create(null) for dictionary object util: use Object.create(null) for dictionary object --- lib/util.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/util.js b/lib/util.js index cf4a65a96750c5..8359699eb91cb3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -159,13 +159,7 @@ function stylizeNoColor(str, styleType) { function arrayToHash(array) { - var hash; - - if (array.indexOf('__proto__') > -1) { - hash = Object.create(null); - } else { - hash = {}; - } + var hash = Object.create(null);; array.forEach(function(val) { hash[val] = true; From 56995c7f97ecda2950a83b2c5f26c02fd6eef294 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Sat, 14 Nov 2015 00:03:58 +0900 Subject: [PATCH 8/9] remove unused --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 8359699eb91cb3..297c59d6b6942b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -159,7 +159,7 @@ function stylizeNoColor(str, styleType) { function arrayToHash(array) { - var hash = Object.create(null);; + var hash = Object.create(null); array.forEach(function(val) { hash[val] = true; From fe4cdc1b9639d11d7487f4eda272147819521abc Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 12 Nov 2015 23:43:36 +0900 Subject: [PATCH 9/9] util: use Object.create(null) for dictionary object --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 18e1dbe49703f8..297c59d6b6942b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -161,7 +161,7 @@ function stylizeNoColor(str, styleType) { function arrayToHash(array) { var hash = Object.create(null); - array.forEach(function(val, idx) { + array.forEach(function(val) { hash[val] = true; });