Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deep-get-set

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-get-set - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

7

index.js

@@ -5,2 +5,6 @@ var hasOwnProp = Object.prototype.hasOwnProperty;

function isSafeKey (key) {
return key !== '__proto__' && key !== 'prototype' && key !== 'constructor';
}
function deep (obj, path, value) {

@@ -15,3 +19,3 @@ if (arguments.length === 3) return set.apply(null, arguments);

var key = keys[i];
if (!obj || !hasOwnProp.call(obj, key)) {
if (!obj || !hasOwnProp.call(obj, key) || !isSafeKey(key)) {
obj = undefined;

@@ -29,2 +33,3 @@ break;

var key = keys[i];
if (!isSafeKey(key)) return;
if (deep.p && !hasOwnProp.call(obj, key)) obj[key] = {};

@@ -31,0 +36,0 @@ obj = obj[key];

2

package.json
{
"name": "deep-get-set",
"description": "Set and get values on objects via dot-notation strings.",
"version": "1.1.0",
"version": "1.1.1",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

@@ -101,1 +101,50 @@ var test = require('tape');

});
test('do not get `__proto__`, `prototype` or `constructor` properties', function (t) {
var obj = {
isAdmin: false,
__proto__: {
isAdmin: true
},
prototype: {
isAdmin: true
},
constructor: {
isAdmin: true,
prototype: {
isAdmin: true
}
}
};
t.equal(deep(obj, 'isAdmin'), false);
t.equal(deep(obj, '__proto__.isAdmin'), undefined);
t.equal(deep(obj, 'prototype.isAdmin'), undefined);
t.equal(deep(obj, 'constructor.isAdmin'), undefined);
t.equal(deep(obj, 'constructor.prototype.isAdmin'), undefined);
t.end();
});
test('do not set `__proto__`, `prototype` or `constructor` properties', function (t) {
var obj = {};
deep.p = true;
deep(obj, 'isAdmin', false);
deep(obj, '__proto__.isAdmin', true);
deep(obj, 'prototype.isAdmin', true);
deep(obj, 'constructor.isAdmin', true);
deep(obj, 'constructor.prototype.isAdmin', true);
t.equal(obj.isAdmin, false);
t.equal(obj.__proto__ && obj.__proto__.isAdmin, undefined);
t.equal(obj.prototype && obj.prototype.isAdmin, undefined);
t.equal(obj.constructor && obj.constructor.isAdmin, undefined);
t.equal(
obj.constructor &&
obj.constructor.prototype &&
obj.constructor.prototype.isAdmin,
undefined
);
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc