Skip to content

Commit cf5c623

Browse files
committed
skip all __ keys instead of only __proto__
1 parent 0dcb1f7 commit cf5c623

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Diff for: src/lib/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ lib.objectFromPath = function(path, value) {
925925
var dottedPropertyRegex = /^([^\[\.]+)\.(.+)?/;
926926
var indexedPropertyRegex = /^([^\.]+)\[([0-9]+)\](\.)?(.+)?/;
927927

928+
function notValid(prop) {
929+
// guard against polluting __proto__ and other internals getters and setters
930+
return prop.slice(0, 2) === '__';
931+
}
932+
928933
lib.expandObjectPaths = function(data) {
929934
var match, key, prop, datum, idx, dest, trailingPath;
930935
if(typeof data === 'object' && !Array.isArray(data)) {
@@ -933,7 +938,7 @@ lib.expandObjectPaths = function(data) {
933938
if((match = key.match(dottedPropertyRegex))) {
934939
datum = data[key];
935940
prop = match[1];
936-
if(prop === '__proto__') continue;
941+
if(notValid(prop)) continue;
937942

938943
delete data[key];
939944

@@ -942,7 +947,7 @@ lib.expandObjectPaths = function(data) {
942947
datum = data[key];
943948

944949
prop = match[1];
945-
if(prop === '__proto__') continue;
950+
if(notValid(prop)) continue;
946951

947952
idx = parseInt(match[2]);
948953

@@ -973,11 +978,11 @@ lib.expandObjectPaths = function(data) {
973978
// This is the case where this property is the end of the line,
974979
// e.g. xaxis.range[0]
975980

976-
if(prop === '__proto__') continue;
981+
if(notValid(prop)) continue;
977982
data[prop][idx] = lib.expandObjectPaths(datum);
978983
}
979984
} else {
980-
if(key === '__proto__') continue;
985+
if(notValid(key)) continue;
981986
data[key] = lib.expandObjectPaths(data[key]);
982987
}
983988
}

0 commit comments

Comments
 (0)