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 6.4.1 to 6.5.0

4

package.json

@@ -9,3 +9,3 @@ {

],
"version": "6.4.1",
"version": "6.5.0",
"homepage": "https://express-validator.github.io",

@@ -46,3 +46,3 @@ "license": "MIT",

"lodash": "^4.17.15",
"validator": "^12.1.0"
"validator": "^13.0.0"
},

@@ -49,0 +49,0 @@ "devDependencies": {

import { SelectFields } from '../select-fields';
import { Request } from '../base';
import { ContextBuilder } from '../context-builder';
import { Context } from '../context';
import { ContextRunner } from './context-runner';
export declare class ContextRunnerImpl implements ContextRunner {
private readonly builder;
private readonly builderOrContext;
private readonly selectFields;
constructor(builder: ContextBuilder, selectFields?: SelectFields);
constructor(builderOrContext: ContextBuilder | Context, selectFields?: SelectFields);
run(req: Request, options?: {
saveContext?: boolean;
}): Promise<import("../context").Context>;
dryRun?: boolean;
}): Promise<Context>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const select_fields_1 = require("../select-fields");
const base_1 = require("../base");
const context_1 = require("../context");
class ContextRunnerImpl {
constructor(builder, selectFields = select_fields_1.selectFields) {
this.builder = builder;
constructor(builderOrContext, selectFields = select_fields_1.selectFields) {
this.builderOrContext = builderOrContext;
this.selectFields = selectFields;
}
async run(req, options = {}) {
const context = this.builder.build();
const context = this.builderOrContext instanceof context_1.Context
? this.builderOrContext
: this.builderOrContext.build();
const instances = this.selectFields(req, context.fields, context.locations);

@@ -17,3 +21,4 @@ context.addFieldInstances(instances);

const promises = context.getData({ requiredOnly: true }).map(async (instance) => {
const instanceKey = `${instance.location}:${instance.path}`;
const { location, path } = instance;
const instanceKey = `${location}:${path}`;
if (haltedInstances.has(instanceKey)) {

@@ -25,5 +30,13 @@ return;

req,
location: instance.location,
path: instance.path,
location,
path,
});
// An instance is mutable, so if an item changed its value, there's no need to call getData again
const newValue = instance.value;
// Checks whether the value changed.
// Avoids e.g. undefined values being set on the request if it didn't have the key initially.
const reqValue = path !== '' ? _.get(req[location], path) : req[location];
if (!options.dryRun && reqValue !== instance.value) {
path !== '' ? _.set(req[location], path, newValue) : _.set(req, location, newValue);
}
}

@@ -40,3 +53,3 @@ catch (e) {

}
if (options.saveContext === undefined || options.saveContext) {
if (!options.dryRun) {
const internalReq = req;

@@ -43,0 +56,0 @@ internalReq[base_1.contextsKey] = (internalReq[base_1.contextsKey] || []).concat(context);

@@ -5,4 +5,4 @@ import { Request } from '../base';

run(req: Request, options?: {
saveContext?: boolean;
dryRun?: boolean;
}): Promise<Context>;
}

@@ -37,2 +37,3 @@ import { CustomValidator } from '../base';

isBoolean(): Chain;
isBtcAddress(): Chain;
isByteLength(options: Options.MinMaxOptions): Chain;

@@ -44,4 +45,6 @@ isCreditCard(): Chain;

isDivisibleBy(number: number): Chain;
isEAN(): Chain;
isEmail(options?: Options.IsEmailOptions): Chain;
isEmpty(options?: Options.IsEmptyOptions): Chain;
isEthereumAddress(): Chain;
isFQDN(options?: Options.IsFQDNOptions): Chain;

@@ -54,2 +57,4 @@ isFloat(options?: Options.IsFloatOptions): Chain;

isHexadecimal(): Chain;
isHSL(): Chain;
isIBAN(): Chain;
isIdentityCard(locale: ['ES'] | 'any'): Chain;

@@ -71,2 +76,3 @@ isIP(version?: Options.IPVersion): Chain;

isLength(options: Options.MinMaxOptions): Chain;
isLocale(): Chain;
isLowercase(): Chain;

@@ -82,5 +88,8 @@ isMagnetURI(): Chain;

isOctal(): Chain;
isPassportNumber(countryCode?: string): Chain;
isPort(): Chain;
isPostalCode(locale: Options.PostalCodeLocale): Chain;
isRFC3339(): Chain;
isRgbColor(includePercentValues?: boolean): Chain;
isSemVer(): Chain;
isSlug(): Chain;

@@ -87,0 +96,0 @@ isSurrogatePair(): Chain;

@@ -93,2 +93,5 @@ "use strict";

}
isBtcAddress() {
return this.addStandardValidation(validator.isBtcAddress);
}
isByteLength(options) {

@@ -106,2 +109,6 @@ return this.addStandardValidation(validator.isByteLength, options);

}
// isDate is not available: https://github.com/validatorjs/validator.js/issues/1304
// isDate() {
// return this.addStandardValidation(validator.isDate);
// }
isDecimal(options) {

@@ -113,2 +120,5 @@ return this.addStandardValidation(validator.isDecimal, options);

}
isEAN() {
return this.addStandardValidation(validator.isEAN);
}
isEmail(options) {

@@ -120,2 +130,5 @@ return this.addStandardValidation(validator.isEmail, options);

}
isEthereumAddress() {
return this.addStandardValidation(validator.isEthereumAddress);
}
isFQDN(options) {

@@ -142,2 +155,8 @@ return this.addStandardValidation(validator.isFQDN, options);

}
isHSL() {
return this.addStandardValidation(validator.isHSL);
}
isIBAN() {
return this.addStandardValidation(validator.isIBAN);
}
isIdentityCard(locale) {

@@ -191,2 +210,5 @@ return this.addStandardValidation(validator.isIdentityCard, locale);

}
isLocale() {
return this.addStandardValidation(validator.isLocale);
}
isLowercase() {

@@ -222,2 +244,5 @@ return this.addStandardValidation(validator.isLowercase);

}
isPassportNumber(countryCode) {
return this.addStandardValidation(validator.isPassportNumber, countryCode);
}
isPort() {

@@ -232,2 +257,8 @@ return this.addStandardValidation(validator.isPort);

}
isRgbColor(includePercentValues) {
return this.addStandardValidation(validator.isRgbColor, includePercentValues);
}
isSemVer() {
return this.addStandardValidation(validator.isSemVer);
}
isSlug() {

@@ -234,0 +265,0 @@ return this.addStandardValidation(validator.isSlug);

@@ -29,2 +29,3 @@ import { CustomValidator, DynamicMessageCreator } from '../base';

isBoolean(): Return;
isBtcAddress(): Return;
isByteLength(options: Options.MinMaxExtendedOptions): Return;

@@ -36,4 +37,6 @@ isCreditCard(): Return;

isDivisibleBy(number: number): Return;
isEAN(): Return;
isEmail(options?: Options.IsEmailOptions): Return;
isEmpty(options?: Options.IsEmptyOptions): Return;
isEthereumAddress(): Return;
isFQDN(options?: Options.IsFQDNOptions): Return;

@@ -46,2 +49,4 @@ isFloat(options?: Options.IsFloatOptions): Return;

isHexadecimal(): Return;
isHSL(): Return;
isIBAN(): Return;
isIdentityCard(locale?: ['ES'] | 'any'): Return;

@@ -63,2 +68,3 @@ isIP(version?: Options.IPVersion): Return;

isLength(options: Options.MinMaxOptions): Return;
isLocale(): Return;
isLowercase(): Return;

@@ -74,5 +80,8 @@ isMagnetURI(): Return;

isOctal(): Return;
isPassportNumber(countryCode?: string): Return;
isPort(): Return;
isPostalCode(locale: Options.PostalCodeLocale): Return;
isRgbColor(includePercentValues?: boolean): Return;
isRFC3339(): Return;
isSemVer(): Return;
isSlug(): Return;

@@ -79,0 +88,0 @@ isSurrogatePair(): Return;

@@ -9,3 +9,3 @@ "use strict";

async run(_context, _value, meta) {
const otherContext = await this.chain.run(meta.req, { saveContext: false });
const otherContext = await this.chain.run(meta.req, { dryRun: true });
if (otherContext.errors.length) {

@@ -12,0 +12,0 @@ throw new base_1.ValidationHalt();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const utils_1 = require("../utils");

@@ -12,3 +11,3 @@ class Sanitization {

async run(context, value, meta) {
const { req, path, location } = meta;
const { path, location } = meta;
const newValue = this.custom

@@ -18,10 +17,4 @@ ? this.sanitizer(value, meta)

context.setData(path, newValue, location);
// Checks whether the value changed.
// Avoids e.g. undefined values being set on the request if it didn't have the key initially.
const reqValue = path !== '' ? _.get(req[location], path) : req[location];
if (reqValue !== newValue) {
path !== '' ? _.set(req[location], path, newValue) : _.set(req, location, newValue);
}
}
}
exports.Sanitization = Sanitization;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const base_1 = require("../base");
const chain_1 = require("../chain");
const context_builder_1 = require("../context-builder");
// A dummy context item that gets added to surrogate contexts just to make them run
const dummyItem = { async run() { } };
function oneOf(chains, message) {
return async (req, _res, next) => {
const surrogateContext = new context_builder_1.ContextBuilder().build();
const surrogateContext = new context_builder_1.ContextBuilder().addItem(dummyItem).build();
// Run each group of chains in parallel, and within each group, run each chain in parallel too.
const promises = chains.map(async (chain) => {
const group = Array.isArray(chain) ? chain : [chain];
const contexts = await Promise.all(group.map(chain => chain.run(req, { saveContext: false })));
const contexts = await Promise.all(group.map(chain => chain.run(req, { dryRun: true })));
const groupErrors = _.flatMap(contexts, 'errors');

@@ -23,3 +25,2 @@ // #536: The data from a chain within oneOf() can only be made available to e.g. matchedData()

});
req[base_1.contextsKey] = (req[base_1.contextsKey] || []).concat(surrogateContext);
try {

@@ -32,2 +33,4 @@ const allErrors = await Promise.all(promises);

}
// Final context running pass to ensure contexts are added and values are modified properly
await new chain_1.ContextRunnerImpl(surrogateContext).run(req);
next();

@@ -34,0 +37,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