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

express-validator

Package Overview
Dependencies
Maintainers
3
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-validator - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1

6

check/check.js

@@ -54,3 +54,7 @@ const validator = require('validator');

middleware.withMessage = message => {
validators[validators.length - 1].message = message;
const lastValidator = validators[validators.length - 1];
if (lastValidator) {
lastValidator.message = message;
}
return middleware;

@@ -57,0 +61,0 @@ };

@@ -10,3 +10,3 @@ const selectFields = require('./select-fields');

validatorCfg.validator(value, { req, location, path }) :
validatorCfg.validator(String(value), ...validatorCfg.options);
validatorCfg.validator(toString(value), ...validatorCfg.options);

@@ -23,3 +23,3 @@ return Promise.resolve(result).then(result => {

value,
msg: validatorCfg.message || err.message
msg: validatorCfg.message || err.message || err
});

@@ -30,2 +30,12 @@ }), Promise.resolve());

return Promise.all(promises).then(() => validationErrors);
};
};
function toString (value) {
if (value && typeof value === 'object' && value.toString) {
return value.toString();
} else if (value == null || (isNaN(value) && !value.length)) {
return '';
}
return String(value);
}

2

index.d.ts

@@ -48,3 +48,3 @@ // Type definitions for express-validator 3.0.0

interface ValidatorFunction {
(item: string | string[], message?: string): Validator;
(item: string | string[], message?: any): Validator;
(schema: {}): Validator;

@@ -51,0 +51,0 @@ }

@@ -173,7 +173,8 @@ var deprecate = require('util').deprecate;

for (var param in schema) {
const paramCfg = schema[param];
// check if schema has defined location
if (schema[param].hasOwnProperty('in')) {
if (allLocations.indexOf(schema[param].in) !== -1) {
currentLoc = schema[param].in;
if (paramCfg.hasOwnProperty('in')) {
if (allLocations.indexOf(paramCfg.in) !== -1) {
currentLoc = paramCfg.in;
} else {

@@ -187,12 +188,8 @@ // skip params where defined location is not supported

const paramErrorMessage = schema[param].errorMessage;
const paramErrorMessage = paramCfg.errorMessage;
var validator = createValidationChain(param, currentLoc, paramErrorMessage, req, contexts);
var opts;
for (var methodName in paramCfg) {
const methodCfg = paramCfg[methodName];
if (schema[param].optional) {
validator.optional.apply(validator, schema[param].optional.options);
}
for (var methodName in schema[param]) {
if (methodName === 'in') {

@@ -207,3 +204,3 @@ /* Skip method if this is location definition, do not validate it.

if (methodName === 'errorMessage' || !schema[param][methodName]) {
if (methodName === 'errorMessage' || !methodCfg) {
// Also do not validate if methodName represent parameter error message

@@ -214,4 +211,3 @@ // or if the value is falsy

opts = schema[param][methodName].options || [];
let opts = methodCfg.options || [];
if (opts != null && !Array.isArray(opts)) {

@@ -221,5 +217,4 @@ opts = [opts];

validator
[methodName](...opts)
.withMessage(schema[param][methodName].errorMessage);
validator[methodName](...opts);
methodName !== 'optional' && validator.withMessage(methodCfg.errorMessage);
}

@@ -226,0 +221,0 @@ }

@@ -36,2 +36,6 @@ var _ = require('lodash');

exports.replaceArgs = function replaceArgs(msg, args) {
if (typeof msg !== 'string') {
return msg;
}
return args.reduce((msg, arg, index) => msg.replace('%' + index, arg), msg);

@@ -38,0 +42,0 @@ };

@@ -14,3 +14,3 @@ {

],
"version": "4.1.0",
"version": "4.1.1",
"homepage": "https://github.com/ctavan/express-validator",

@@ -17,0 +17,0 @@ "license": "MIT",

@@ -185,3 +185,3 @@ export type URLProtocol = 'http' | 'https' | 'ftp'

options?: any[]
errorMessage?: string
errorMessage?: any
}

@@ -191,3 +191,3 @@

in?: Location
errorMessage?: string
errorMessage?: any

@@ -194,0 +194,0 @@ // Additional ValidatorChain.prototype.* validators

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