Skip to content

Commit

Permalink
use "has" instead of home rolled hasOwnProperty wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeck committed Oct 6, 2014
1 parent 198708e commit 8e6f9c2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 42 deletions.
5 changes: 3 additions & 2 deletions lib/ipset/add.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var exec = require('../child_utils').exec;
var hasOwnProperty = require('has');

/**
* Add a given entry to the set.
Expand Down Expand Up @@ -37,7 +38,7 @@ module.exports = function (options, cb) {
*/
if (typeof options['add_options'] != 'undefined') {
for (var i in options['add_options']) {
if (options['add_options'].hasOwnProperty(i)) {
if (hasOwnProperty(options['add_options'], i)) {
args = args.concat(i, options['add_options'][i]);
}
}
Expand All @@ -58,4 +59,4 @@ module.exports = function (options, cb) {
cb(null);
}
});
};
};
5 changes: 3 additions & 2 deletions lib/ipset/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var exec = require('../child_utils').exec;
var hasOwnProperty = require('has');

/**
* Create a set identified with setsetname and specified type.
Expand Down Expand Up @@ -37,7 +38,7 @@ module.exports = function (options, cb) {
*/
if (typeof options['create_options'] != 'undefined') {
for (var i in options['create_options']) {
if (options['create_options'].hasOwnProperty(i)) {
if (hasOwnProperty(options['create_options'], i)) {
args = args.concat(i, options['create_options'][i]);
}
}
Expand All @@ -58,4 +59,4 @@ module.exports = function (options, cb) {
cb(null);
}
});
};
};
5 changes: 3 additions & 2 deletions lib/ipset/del.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var exec = require('../child_utils').exec;
var hasOwnProperty = require('has');

/**
* Delete an entry from a set.
Expand Down Expand Up @@ -37,7 +38,7 @@ module.exports = function (options, cb) {
*/
if (typeof options['del_options'] != 'undefined') {
for (var i in options['del_options']) {
if (options['del_options'].hasOwnProperty(i)) {
if (hasOwnProperty(options['del_options'], i)) {
args = args.concat(i, options['del_options'][i]);
}
}
Expand All @@ -58,4 +59,4 @@ module.exports = function (options, cb) {
cb(null);
}
});
};
};
5 changes: 3 additions & 2 deletions lib/ipset/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var exec = require('../child_utils').exec;
var hasOwnProperty = require('has');

/**
* Test wether an entry is in a set or not.
Expand Down Expand Up @@ -37,7 +38,7 @@ module.exports = function (options, cb) {
*/
if (typeof options['test_options'] != 'undefined') {
for (var i in options['test_options']) {
if (options['test_options'].hasOwnProperty(i)) {
if (hasOwnProperty(options['test_options'], i)) {
args = args.concat(i, options['test_options'][i]);
}
}
Expand All @@ -58,4 +59,4 @@ module.exports = function (options, cb) {
cb(null, 0);
}
});
};
};
5 changes: 3 additions & 2 deletions lib/iptables/dump.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var hasOwnProperty = require('has');
var exec = require('../child_utils').exec;
var shell_quote = require('shell-quote');

Expand Down Expand Up @@ -223,7 +224,7 @@ module.exports = function (/* options?, cb */) {

args.forEach(function (arg) {
if (option === '') {
arg = Object.prototype.hasOwnProperty.call(MAPPED_ARGS, arg)
arg = hasOwnProperty(MAPPED_ARGS, arg)
? MAPPED_ARGS[arg]
: arg;

Expand Down Expand Up @@ -328,4 +329,4 @@ module.exports = function (/* options?, cb */) {
cb(null, tables);
}
});
};
};
16 changes: 4 additions & 12 deletions lib/iptables/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// protect against .hasOwnProperty attacks
var hasOwnProperty = require('has');

// Tables.
exports.tables = {
filter : 'filter', // The default table (if no -t option is passed). It contains the built-in chains INPUT (for packets destined to local sockets), FORWARD (for packets being routed through the box), and OUTPUT (for locally-generated packets).
Expand Down Expand Up @@ -38,17 +41,6 @@ function manage_arg(property, flag, args, is_boolean) {
}
}

/**
* TODO: Ask @bmeck the reasoning behind overriding the native method.
*
* @param {Object} object Object to be tested for property inclusion.
* @param {String} key Property to be tested against the object.
* @return {Boolean}
*/
function hasOwnProperty(object, key) {
return Object.prototype.hasOwnProperty.call(object, key);
}

/**
* Process common rule specs for `append`, `check`, `delete`, `insert` and `replace`.
*
Expand Down Expand Up @@ -106,4 +98,4 @@ exports.processCommonRuleSpecs = function (options) {
}

return args;
};
};
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name" : "netfilter",
"version" : "0.3.0",
"description" : "Packet filtering framework. Wrapper to provide netfilter capabilities from Node.js",
"main" : "index.js",
"keywords" : [
"name": "netfilter",
"version": "0.3.0",
"description": "Packet filtering framework. Wrapper to provide netfilter capabilities from Node.js",
"main": "index.js",
"keywords": [
"stateless",
"stateful",
"packet",
Expand All @@ -27,32 +27,33 @@
"alias",
"set"
],
"dependencies" : {
"async" : "~0.9.0",
"dependencies": {
"async": "~0.9.0",
"has": "0.0.1",
"process-queue": "^1.0.1",
"shell-quote" : "^1.4.2"
"shell-quote": "^1.4.2"
},
"devDependencies": {
"should": "~4.0.4",
"mocha" : "~1.20.1"
"mocha": "^1.21.4",
"should": "^4.0.4"
},
"engines" : {
"engines": {
"node": ">=0.8.0"
},
"homepage" : "https://github.com/diosney/node-netfilter",
"bugs" : {
"homepage": "https://github.com/diosney/node-netfilter",
"bugs": {
"url": "https://github.com/diosney/node-netfilter/issues"
},
"author" : {
"name" : "Diosney Sarmiento",
"author": {
"name": "Diosney Sarmiento",
"email": "[email protected]"
},
"license" : "MIT",
"repository" : {
"license": "MIT",
"repository": {
"type": "git",
"url" : "https://github.com/diosney/node-netfilter.git"
"url": "https://github.com/diosney/node-netfilter.git"
},
"scripts" : {
"test": "node test/*.js"
"scripts": {
"test": "mocha test/unit/*.js"
}
}

0 comments on commit 8e6f9c2

Please sign in to comment.