Comparing version 13.4.0 to 13.5.0
@@ -135,3 +135,3 @@ 'use strict'; | ||
const options = count === 2 ? args[1] : {}; | ||
const options = count === 2 ? args[1] : undefined; | ||
const schema = root.compile(args[0]); | ||
@@ -138,0 +138,0 @@ |
@@ -150,2 +150,3 @@ 'use strict'; | ||
base64: 'must be a valid base64 string', | ||
dataUri: 'must be a valid dataUri string', | ||
hostname: 'must be a valid hostname', | ||
@@ -152,0 +153,0 @@ normalize: 'must be unicode normalized in the {{form}} form', |
@@ -480,3 +480,3 @@ 'use strict'; | ||
unique(comparator) { | ||
unique(comparator, configs) { | ||
@@ -487,4 +487,10 @@ Hoek.assert(comparator === undefined || | ||
const settings = {}; | ||
Hoek.assert(configs === undefined || | ||
typeof configs === 'object', 'configs must be an object'); | ||
const settings = { | ||
ignoreUndefined: (configs && configs.ignoreUndefined) || false | ||
}; | ||
if (typeof comparator === 'string') { | ||
@@ -510,2 +516,3 @@ settings.path = comparator; | ||
const compare = settings.comparator || Hoek.deepEqual; | ||
const ignoreUndefined = settings.ignoreUndefined; | ||
@@ -549,3 +556,3 @@ for (let i = 0; i < value.length; ++i) { | ||
else { | ||
if (records[item] !== undefined) { | ||
if ((!ignoreUndefined || item !== undefined) && records[item] !== undefined) { | ||
const localState = { | ||
@@ -552,0 +559,0 @@ key: state.key, |
@@ -279,2 +279,3 @@ 'use strict'; | ||
let relativeOnly = false; | ||
let allowQuerySquareBrackets = false; | ||
let regex = internals.uriRegex; | ||
@@ -285,2 +286,5 @@ | ||
const unknownOptions = Object.keys(uriOptions).filter((key) => !['scheme', 'allowRelative', 'relativeOnly', 'allowQuerySquareBrackets'].includes(key)); | ||
Hoek.assert(unknownOptions.length === 0, `options contain unknown keys: ${unknownOptions}`); | ||
if (uriOptions.scheme) { | ||
@@ -321,6 +325,10 @@ Hoek.assert(uriOptions.scheme instanceof RegExp || typeof uriOptions.scheme === 'string' || Array.isArray(uriOptions.scheme), 'scheme must be a RegExp, String, or Array'); | ||
} | ||
if (uriOptions.allowQuerySquareBrackets) { | ||
allowQuerySquareBrackets = true; | ||
} | ||
} | ||
if (customScheme || allowRelative || relativeOnly) { | ||
regex = Uri.createUriRegex(customScheme, allowRelative, relativeOnly); | ||
if (customScheme || allowRelative || relativeOnly || allowQuerySquareBrackets) { | ||
regex = Uri.createUriRegex(customScheme, allowRelative, relativeOnly, allowQuerySquareBrackets); | ||
} | ||
@@ -466,2 +474,37 @@ | ||
dataUri(dataUriOptions = {}) { | ||
const regex = /^data:[\w\/\+]+;((charset=[\w-]+|base64),)?(.*)$/; | ||
// Determine if padding is required. | ||
const paddingRequired = dataUriOptions.paddingRequired === false ? | ||
dataUriOptions.paddingRequired | ||
: dataUriOptions.paddingRequired || true; | ||
const base64regex = paddingRequired ? | ||
/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/ | ||
: /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}(==)?|[A-Za-z0-9+\/]{3}=?)?$/; | ||
return this._test('dataUri', regex, function (value, state, options) { | ||
const matches = value.match(regex); | ||
if (matches) { | ||
if (!matches[2]) { | ||
return value; | ||
} | ||
if (matches[2] !== 'base64') { | ||
return value; | ||
} | ||
if (base64regex.test(matches[3])) { | ||
return value; | ||
} | ||
} | ||
return this.createError('string.dataUri', { value }, state, options); | ||
}); | ||
} | ||
hostname() { | ||
@@ -536,16 +579,29 @@ | ||
trim() { | ||
trim(enabled = true) { | ||
const obj = this._test('trim', undefined, function (value, state, options) { | ||
Hoek.assert(typeof enabled === 'boolean', 'option must be a boolean'); | ||
if (options.convert || | ||
value === value.trim()) { | ||
if ((this._flags.trim && enabled) || (!this._flags.trim && !enabled)) { | ||
return this; | ||
} | ||
return value; | ||
} | ||
let obj; | ||
if (enabled) { | ||
obj = this._test('trim', undefined, function (value, state, options) { | ||
return this.createError('string.trim', { value }, state, options); | ||
}); | ||
if (options.convert || | ||
value === value.trim()) { | ||
obj._flags.trim = true; | ||
return value; | ||
} | ||
return this.createError('string.trim', { value }, state, options); | ||
}); | ||
} | ||
else { | ||
obj = this.clone(); | ||
obj._tests = obj._tests.filter((test) => test.name !== 'trim'); | ||
} | ||
obj._flags.trim = enabled; | ||
return obj; | ||
@@ -552,0 +608,0 @@ } |
@@ -82,2 +82,7 @@ 'use strict'; | ||
/** | ||
* squareBrackets example: [] | ||
*/ | ||
const squareBrackets = '\\[\\]'; | ||
/** | ||
* dec-octet = DIGIT ; 0-9 | ||
@@ -202,2 +207,7 @@ * / %x31-39 DIGIT ; 10-99 | ||
/** | ||
* query = *( pchar / "[" / "]" / "/" / "?" ) | ||
*/ | ||
internals.rfc3986.queryWithSquareBrackets = '[' + pchar + squareBrackets + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line. | ||
/** | ||
* fragment = *( pchar / "/" / "?" ) | ||
@@ -204,0 +214,0 @@ */ |
@@ -12,3 +12,3 @@ 'use strict'; | ||
Uri: { | ||
createUriRegex: function (optionalScheme, allowRelative, relativeOnly) { | ||
createUriRegex: function (optionalScheme, allowRelative, relativeOnly, allowQuerySquareBrackets) { | ||
@@ -41,3 +41,3 @@ let scheme = RFC3986.scheme; | ||
*/ | ||
return new RegExp('^' + prefix + '(?:\\?' + RFC3986.query + ')?' + '(?:#' + RFC3986.fragment + ')?$'); | ||
return new RegExp('^' + prefix + '(?:\\?' + (allowQuerySquareBrackets ? RFC3986.queryWithSquareBrackets : RFC3986.query) + ')?' + '(?:#' + RFC3986.fragment + ')?$'); | ||
} | ||
@@ -44,0 +44,0 @@ } |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "13.4.0", | ||
"version": "13.5.0", | ||
"homepage": "https://github.com/hapijs/joi", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hapijs/joi", |
@@ -19,3 +19,3 @@ ![joi Logo](https://raw.github.com/hapijs/joi/master/images/joi.png) | ||
# API | ||
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v13.4.0/API.md). | ||
See the detailed [API Reference](https://github.com/hapijs/joi/blob/v13.5.0/API.md). | ||
@@ -22,0 +22,0 @@ # Example |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179887
4257