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

joi

Package Overview
Dependencies
Maintainers
4
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi - npm Package Compare versions

Comparing version 10.5.2 to 10.6.0

6

lib/index.js

@@ -333,3 +333,7 @@ 'use strict';

if (rule.setup) {
rule.setup.call(schema, arg);
const newSchema = rule.setup.call(schema, arg);
if (newSchema !== undefined) {
Hoek.assert(newSchema instanceof Any, `Setup of extension Joi.${this._type}().${rule.name}() must return undefined or a Joi object`);
schema = newSchema;
}
}

@@ -336,0 +340,0 @@

@@ -45,2 +45,3 @@ 'use strict';

orderedLength: 'at position {{pos}} fails because array must contain at most {{limit}} items',
ref: 'references "{{ref}}" which is not a positive integer',
sparse: 'must not be a sparse array',

@@ -47,0 +48,0 @@ unique: 'position {{pos}} contains a duplicate value'

@@ -7,2 +7,3 @@ 'use strict';

const Cast = require('../../cast');
const Ref = require('../../ref');
const Hoek = require('hoek');

@@ -394,7 +395,21 @@

Hoek.assert(Number.isSafeInteger(limit) && limit >= 0, 'limit must be a positive integer');
const isRef = Ref.isRef(limit);
Hoek.assert((Number.isSafeInteger(limit) && limit >= 0) || isRef, 'limit must be a positive integer or reference');
return this._test('min', limit, function (value, state, options) {
if (value.length >= limit) {
let compareTo;
if (isRef) {
compareTo = limit(state.reference || state.parent, options);
if (!(Number.isSafeInteger(compareTo) && compareTo >= 0)) {
return this.createError('array.ref', { ref: limit.key }, state, options);
}
}
else {
compareTo = limit;
}
if (value.length >= compareTo) {
return value;

@@ -409,7 +424,21 @@ }

Hoek.assert(Number.isSafeInteger(limit) && limit >= 0, 'limit must be a positive integer');
const isRef = Ref.isRef(limit);
Hoek.assert((Number.isSafeInteger(limit) && limit >= 0) || isRef, 'limit must be a positive integer or reference');
return this._test('max', limit, function (value, state, options) {
if (value.length <= limit) {
let compareTo;
if (isRef) {
compareTo = limit(state.reference || state.parent, options);
if (!(Number.isSafeInteger(compareTo) && compareTo >= 0)) {
return this.createError('array.ref', { ref: limit.key }, state, options);
}
}
else {
compareTo = limit;
}
if (value.length <= compareTo) {
return value;

@@ -424,7 +453,21 @@ }

Hoek.assert(Number.isSafeInteger(limit) && limit >= 0, 'limit must be a positive integer');
const isRef = Ref.isRef(limit);
Hoek.assert((Number.isSafeInteger(limit) && limit >= 0) || isRef, 'limit must be a positive integer or reference');
return this._test('length', limit, function (value, state, options) {
if (value.length === limit) {
let compareTo;
if (isRef) {
compareTo = limit(state.reference || state.parent, options);
if (!(Number.isSafeInteger(compareTo) && compareTo >= 0)) {
return this.createError('array.ref', { ref: limit.key }, state, options);
}
}
else {
compareTo = limit;
}
if (value.length === compareTo) {
return value;

@@ -431,0 +474,0 @@ }

81

lib/types/string/index.js

@@ -18,3 +18,13 @@ 'use strict';

uriRegex: Uri.createUriRegex(),
ipRegex: Ip.createIpRegex(['ipv4', 'ipv6', 'ipvfuture'], 'optional')
ipRegex: Ip.createIpRegex(['ipv4', 'ipv6', 'ipvfuture'], 'optional'),
guidBrackets: {
'{': '}', '[': ']', '(': ')', '': ''
},
guidVersions: {
uuidv1: '1',
uuidv2: '2',
uuidv3: '3',
uuidv4: '4',
uuidv5: '5'
}
};

@@ -330,16 +340,4 @@

const brackets = {
'{': '}', '[': ']', '(': ')', '': ''
};
let versionNumbers = '';
const uuids = {
'uuidv1': '1',
'uuidv2': '2',
'uuidv3': '3',
'uuidv4': '4',
'uuidv5': '5'
};
const versions = [];
if (guidOptions && guidOptions.version) {

@@ -351,2 +349,3 @@ if (!Array.isArray(guidOptions.version)) {

Hoek.assert(guidOptions.version.length >= 1, 'version must have at least 1 valid version specified');
const versions = new Set();

@@ -357,13 +356,16 @@ for (let i = 0; i < guidOptions.version.length; ++i) {

version = version.toLowerCase();
Hoek.assert(uuids[version], 'version at position ' + i + ' must be one of ' + Object.keys(uuids).join(', '));
Hoek.assert(versions.indexOf(version) === -1, 'version at position ' + i + ' must not be a duplicate.');
versions.push(version);
const versionNumber = internals.guidVersions[version];
Hoek.assert(versionNumber, 'version at position ' + i + ' must be one of ' + Object.keys(internals.guidVersions).join(', '));
Hoek.assert(!(versions.has(versionNumber)), 'version at position ' + i + ' must not be a duplicate.');
versionNumbers += versionNumber;
versions.add(versionNumber);
}
}
const regex = /^([\[{\(]?)([0-9A-F]{8})([:-]?)([0-9A-F]{4})([:-]?)([0-9A-F]{4})([:-]?)([0-9A-F]{4})([:-]?)([0-9A-F]{12})([\]}\)]?)$/i;
const guidRegex = new RegExp(`^([\\[{\\(]?)[0-9A-F]{8}([:-]?)[0-9A-F]{4}\\2?[${versionNumbers || '0-9A-F'}][0-9A-F]{3}\\2?[${versionNumbers ? '89AB' : '0-9A-F'}][0-9A-F]{3}\\2?[0-9A-F]{12}([\\]}\\)]?)$`, 'i');
return this._test('guid', guidOptions, function (value, state, options) {
const results = regex.exec(value);
const results = guidRegex.exec(value);

@@ -375,24 +377,6 @@ if (!results) {

// Matching braces
if (brackets[results[1]] !== results[11]) {
if (internals.guidBrackets[results[1]] !== results[results.length - 1]) {
return this.createError('string.guid', { value }, state, options);
}
// Matching separators
if (results[3] !== results[5] || results[3] !== results[7] || results[3] !== results[9]) {
return this.createError('string.guid', { value }, state, options);
}
// Specific UUID versions
if (versions.length) {
const validVersions = versions.some((uuidVersion) => {
return results[6][0] === uuids[uuidVersion];
});
// Valid version and 89AB check
if (!(validVersions && /[89AB]/i.test(results[8][0]))) {
return this.createError('string.guid', { value }, state, options);
}
}
return value;

@@ -416,6 +400,23 @@ });

base64() {
base64(base64Options) {
const regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;
base64Options = base64Options || {};
// Validation.
Hoek.assert(typeof base64Options === 'object', 'base64 options must be an object');
Hoek.assert(typeof base64Options.paddingRequired === 'undefined' || typeof base64Options.paddingRequired === 'boolean',
'paddingRequired must be boolean');
// Determine if padding is required.
const paddingRequired = base64Options.paddingRequired === false ?
base64Options.paddingRequired
: base64Options.paddingRequired || true;
// Set validation based on preference.
const regex = paddingRequired ?
// Padding is required.
/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/
// Padding is optional.
: /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}(==)?|[A-Za-z0-9+\/]{3}=?)?$/;
return this._test('base64', regex, function (value, state, options) {

@@ -422,0 +423,0 @@

{
"name": "joi",
"description": "Object schema validation",
"version": "10.5.2",
"version": "10.6.0",
"homepage": "https://github.com/hapijs/joi",

@@ -6,0 +6,0 @@ "repository": "git://github.com/hapijs/joi",

@@ -128,3 +128,3 @@ ![joi Logo](https://raw.github.com/hapijs/joi/master/images/joi.png)

# API
See the [API Reference](https://github.com/hapijs/joi/blob/v10.5.2/API.md).
See the [API Reference](https://github.com/hapijs/joi/blob/v10.6.0/API.md).

@@ -131,0 +131,0 @@ # Browsers

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