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

sanitize

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sanitize - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

3

lib/middleware.js

@@ -67,2 +67,5 @@ /**

};
req.queryArray = function(name, type) {
return req.sanitizer.array(req.query[name], type || 'str');
};

@@ -69,0 +72,0 @@ // functions to retrieve and filter param middleware

23

lib/sanitize.js

@@ -24,2 +24,13 @@ /**

});
},
array: function(values, type) {
var invalid = false;
var values = _.map(values, function(value) {
value = filterValue(value, type);
if (!invalid && (isNaN(value) || _.isUndefined(value) || _.isNull(value))) {
invalid = true;
}
return value;
});
return !invalid ? values : null;
}

@@ -53,4 +64,4 @@ };

return function(value, type, callback) {
return applySanitizerForType(value, type, sanitizer);
return function(value, type) {
return applySanitizerForType.call(sanitizer, value, type);
};

@@ -60,3 +71,3 @@ }

function applySanitizerForType(value, type, sanitizer) {
function applySanitizerForType(value, type) {

@@ -73,3 +84,3 @@ // if value is undefined, fast fail

if (!_.isString(type)) {
parts = sanitizer.getImplicitType(type);
parts = this.getImplicitType(type);

@@ -87,6 +98,6 @@ if (!_.isArray(parts)) {

type = sanitizer.aliases.lookup(type);
type = this.aliases.lookup(type);
return sanitizer[type].apply(sanitizer, parts);
return this[type].apply(this, parts);
}

@@ -41,3 +41,8 @@ /**

float: function(value, arg) {
float: function(value) {
var arg;
if (_.isArray(value)) {
arg = value[1];
value = value[0];
}
try {

@@ -44,0 +49,0 @@ var flo = parseFloat(value);

{
"name": "sanitize",
"version": "0.0.4",
"version": "0.0.5",
"description": "Input sanitizing library for node.js",

@@ -5,0 +5,0 @@ "main": "lib/sanitize.js",

@@ -86,2 +86,7 @@ /**

{
type: 'flo',
value: ['1.123456', 2],
expected: 1.12
},
{
type: 'float',

@@ -366,2 +371,45 @@ value: null,

describe('array()', function() {
var tests = [
{
shouldBe: 'should validate an array of valid values',
expected: [1,2,3],
values: ['1','2','3'],
type: 'int'
},
{
shouldBe: 'should invalidate an array with at least one invalid value',
expected: null,
values: ['1',null,'3'],
type: 'int'
},
{
shouldBe: 'should invalidate an array with a NaN',
expected: null,
values: ['1',NaN,'3'],
type: 'int'
},
{
shouldBe: 'should invalidate an array with an undefined',
expected: null,
values: ['1',undefined,'3'],
type: 'int'
}
];
_.each(tests, function(test) {
it(test.shouldBe, function() {
if (test.expected) {
test.expected.should.be.eql(sanitizer.array(test.values, test.type));
} else {
(test.expected === sanitizer.array(test.values, test.type)).should.be.ok;
}
});
});
});
});

@@ -368,0 +416,0 @@

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