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

mongojs-hooks

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongojs-hooks - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

8

mongojs-hooks.js

@@ -68,3 +68,3 @@ var mongojs = require("mongojs");

sanitise: function (object) {
if (!object)
if (!object || object._bsontype)
return object;

@@ -75,3 +75,3 @@

var newObject = { };
var newObject = _.isArray(object) ? [ ] : { };

@@ -98,3 +98,3 @@ Object.keys(object).forEach(function (key) {

unsanitise: function (object) {
if (!object)
if (!object || object._bsontype)
return object;

@@ -105,3 +105,3 @@

var newObject = { };
var newObject = _.isArray(object) ? [ ] : { };

@@ -108,0 +108,0 @@ Object.keys(object).forEach(function (sKey) {

{
"name": "mongojs-hooks",
"description": "Wrap monogjs in pre and post hooks",
"version": "0.1.5",
"version": "0.1.6",
"main": "./mongojs-hooks",

@@ -6,0 +6,0 @@ "author": {

@@ -87,3 +87,40 @@ var mongo = require("../mongojs-hooks");

});
it("should skip object if it contains a _bsontype key", function () {
// These are special Mongo objects so don't malform them
var object = {
_bsontype: "ObjectID",
"test.this": "ignore"
};
var sanitised = mongo.util.sanitise(object);
sanitised.should.not.have.property("testU+FF0Ethis");
sanitised.should.have.property("test.this");
});
});
describe("when an Array", function () {
it("should maintain all elements in the array", function () {
var array = [
{ key: "value" },
{ second: "object" }
];
var sanitised = mongo.util.sanitise(array);
(sanitised instanceof Array).should.be.true;
sanitised.length.should.equal(2);
sanitised.should.deep.equal(array);
});
it("should sanitise keys in any elements", function () {
var array = [
{ "test.one": "value" },
{ "test.two": "object" }
];
var sanitised = mongo.util.sanitise(array);
sanitised[0].should.have.property("testU+FF0Eone");
sanitised[1].should.have.property("testU+FF0Etwo");
});
});
});

@@ -174,4 +211,41 @@

});
it("should skip object if it contains a _bsontype key", function () {
// These are special Mongo objects so don't malform them
var object = {
_bsontype: "ObjectID",
"testU+FF0Ethis": "ignore"
};
var unsanitised = mongo.util.unsanitise(object);
unsanitised.should.not.have.property("test.this");
unsanitised.should.have.property("testU+FF0Ethis");
});
});
describe("when an Array", function () {
it("should maintain all elements in the array", function () {
var array = [
{ key: "value" },
{ second: "object" }
];
var unsanitised = mongo.util.unsanitise(array);
(unsanitised instanceof Array).should.be.true;
unsanitised.length.should.equal(2);
unsanitised.should.deep.equal(array);
});
it("should unsanitise keys in any elements", function () {
var array = [
{ "testU+FF0Eone": "value" },
{ "testU+FF0Etwo": "object" }
];
var unsanitised = mongo.util.unsanitise(array);
unsanitised[0].should.have.property("test.one");
unsanitised[1].should.have.property("test.two");
});
});
});
});
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