Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / configstore / node_modules / dot-prop / index.js
index 15282bb392402ed8bae316ed244671c9aa265952..189831cf00f81d0d2d8359c354aef70747410e7a 100644 (file)
@@ -1,6 +1,14 @@
 'use strict';
 const isObj = require('is-obj');
 
+const disallowedKeys = [
+       '__proto__',
+       'prototype',
+       'constructor'
+];
+
+const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.includes(segment));
+
 function getPathSegments(path) {
        const pathArr = path.split('.');
        const parts = [];
@@ -16,6 +24,10 @@ function getPathSegments(path) {
                parts.push(p);
        }
 
+       if (!isValidPath(parts)) {
+               return [];
+       }
+
        return parts;
 }
 
@@ -26,6 +38,9 @@ module.exports = {
                }
 
                const pathArr = getPathSegments(path);
+               if (pathArr.length === 0) {
+                       return;
+               }
 
                for (let i = 0; i < pathArr.length; i++) {
                        if (!Object.prototype.propertyIsEnumerable.call(obj, pathArr[i])) {
@@ -58,6 +73,9 @@ module.exports = {
 
                const root = obj;
                const pathArr = getPathSegments(path);
+               if (pathArr.length === 0) {
+                       return;
+               }
 
                for (let i = 0; i < pathArr.length; i++) {
                        const p = pathArr[i];