1 | var namespace = require('./namespace');
|
2 |
|
3 | /**
|
4 | * set "nested" object property
|
5 | */
|
6 | function set(obj, prop, val){
|
7 | var stringifiedProp = prop.toString();
|
8 | // prototype pollution mitigation
|
9 | if(stringifiedProp.includes('__proto__') || stringifiedProp.includes('prototype') || stringifiedProp.includes('constructor')) {
|
10 | return false;
|
11 | }
|
12 | var parts = (/^(.+)\.(.+)$/).exec(stringifiedProp);
|
13 | if (parts){
|
14 | namespace(obj, parts[1])[parts[2]] = val;
|
15 | } else {
|
16 | obj[stringifiedProp] = val;
|
17 | }
|
18 | }
|
19 |
|
20 | module.exports = set;
|
21 |
|
22 |
|