diff --git a/API.md b/API.md index 70bbef7b8..cab4586b8 100755 --- a/API.md +++ b/API.md @@ -2598,7 +2598,7 @@ const schema = Joi.string().min(1).max(10); await schema.validate('12345'); ``` -Possible validation errors: [`string.base`](#stringbase), [`any.empty`](#anyempty) +Possible validation errors: [`string.base`](#stringbase), [`string.empty`](#stringempty) #### `string.alphanum()` @@ -3268,17 +3268,6 @@ Additional local context properties: } ``` -#### `any.empty` - -When an empty string is found and denied by invalid values. - -Additional local context properties: -```ts -{ - invalids: Array // Contains the list of the invalid values that should be rejected -} -``` - #### `any.invalid` The value matched a value listed in the invalid values. @@ -4041,6 +4030,10 @@ Additional local context properties: } ``` +#### `string.empty` + +When an empty string is found and denied by invalid values. + #### `string.guid` The string is not a valid GUID. diff --git a/lib/messages.js b/lib/messages.js index 37003aec4..0a60f6d7e 100755 --- a/lib/messages.js +++ b/lib/messages.js @@ -118,7 +118,6 @@ exports.errors = { 'alternatives.types': '"{{#label}}" must be one of {{#types}}', 'any.default': '"{{#label}}" threw an error when running default method', - 'any.empty': '"{{#label}}" is not allowed to be empty', 'any.failover': '"{{#label}}" threw an error when running failover method', 'any.invalid': '"{{#label}}" contains an invalid value', 'any.only': '"{{#label}}" must be one of {{#valids}}', @@ -216,6 +215,7 @@ exports.errors = { 'string.dataUri': '"{{#label}}" must be a valid dataUri string', 'string.domain': '"{{#label}}" must contain a valid domain name', 'string.email': '"{{#label}}" must be a valid email', + 'string.empty': '"{{#label}}" is not allowed to be empty', 'string.guid': '"{{#label}}" must be a valid GUID', 'string.hex': '"{{#label}}" must only contain hexadecimal characters', 'string.hexAlign': '"{{#label}}" hex decoded representation must be byte aligned', diff --git a/lib/types/any.js b/lib/types/any.js index f867c8f98..abb6f74f9 100755 --- a/lib/types/any.js +++ b/lib/types/any.js @@ -452,7 +452,7 @@ module.exports = internals.Any = class { obj._ruleset = source._ruleset === false ? false : source._ruleset + obj._tests.length; } - // Combine tests + // Rules for (const test of source._tests) { if (!test.func && @@ -464,6 +464,8 @@ module.exports = internals.Any = class { obj._tests.push(test); } + // Flags + if (obj._flags.empty && source._flags.empty) { @@ -482,6 +484,8 @@ module.exports = internals.Any = class { Hoek.merge(obj._flags, source._flags); } + // Inners + for (const key in source._inners) { const inners = source._inners[key]; if (!inners) { @@ -877,14 +881,14 @@ module.exports = internals.Any = class { return obj; } - _state(path, ancestors, state, options = {}) { + _state(path, ancestors, state) { return { path, ancestors, mainstay: state.mainstay, - flags: options.flags !== false ? this._flags : {}, - schemas: options.schemas ? [this, ...state.schemas] : state.schemas + flags: this._flags, + schemas: state.schemas }; } diff --git a/lib/types/object.js b/lib/types/object.js index 1af324b32..a2fcd6550 100755 --- a/lib/types/object.js +++ b/lib/types/object.js @@ -235,7 +235,9 @@ internals.Object = Any.extend({ const forbidUnknown = !Common.default(this._flags.unknown, prefs.allowUnknown); if (forbidUnknown) { for (const unprocessedKey of unprocessed) { - const localState = this._state([...state.path, unprocessedKey], [], state, { flags: false }); + const localState = this._state([...state.path, unprocessedKey], [], state); + localState.flags = {}; + const report = this.createError('object.unknown', value[unprocessedKey], { child: unprocessedKey }, localState, prefs); if (prefs.abortEarly) { return { value, errors: report }; diff --git a/lib/types/string/index.js b/lib/types/string/index.js index 40da6a182..0c90aae6d 100755 --- a/lib/types/string/index.js +++ b/lib/types/string/index.js @@ -5,7 +5,6 @@ const Hoek = require('@hapi/hoek'); const Any = require('../any'); const Common = require('../../common'); -const Values = require('../../values'); const Ip = require('./ip'); const Uri = require('./uri'); @@ -61,7 +60,6 @@ internals.String = Any.extend({ initialize: function () { - this._invalids = new Values(['']); this._inners.replacements = null; }, @@ -143,6 +141,10 @@ internals.String = Any.extend({ if (typeof value !== 'string') { return { value, errors: this.createError('string.base', value, null, state, prefs) }; } + + if (value === '') { + return { value, errors: this.createError('string.empty', value, null, state, prefs) }; + } }, // Rules diff --git a/lib/validator.js b/lib/validator.js index 8ea8cb71b..eb5e2791c 100755 --- a/lib/validator.js +++ b/lib/validator.js @@ -25,9 +25,6 @@ exports.entry = function (value, schema, prefs) { Hoek.assert(!mainstay.externals.length || settings.externals, 'Cannot validate a schema with external rules without the externals flag'); - this.value = value; - this.error = error; - const outcome = { value: result.value, error }; if (mainstay.warnings.length) { outcome.warning = Errors.details(mainstay.warnings); @@ -43,56 +40,21 @@ exports.entry = function (value, schema, prefs) { }; -internals.externals = function (externals, outcome, prefs) { - - return new Promise(async (resolve, reject) => { - - let root = outcome.value; - - for (const { method, path, label } of externals) { - let value = root; - let key; - let parent; - - if (path.length) { - key = path[path.length - 1]; - parent = Hoek.reach(root, path.slice(0, -1)); - value = parent[key]; - } - - try { - var result = await method(value); - } - catch (err) { - err.message += ` (${label})`; - return reject(err); // Change message to include path - } - - if (result === undefined || - result === value) { - - continue; - } - - if (parent) { - parent[key] = result; - } - else { - root = result; - } - } - - resolve(prefs.warnings ? Object.assign(outcome, { value: root }) : root); - }); -}; - - exports.validate = function (value, schema, state, prefs) { // Setup state and settings - state = schema._state(state.path, state.ancestors, state, { schemas: true }); - prefs = internals.prefs(schema, prefs); + state = { + path: state.path, + ancestors: state.ancestors, + mainstay: state.mainstay, + flags: schema._flags, + schemas: [schema, ...state.schemas] + }; + + if (schema._preferences) { + prefs = internals.prefs(schema, prefs); + } const original = value; @@ -186,7 +148,7 @@ exports.validate = function (value, schema, state, prefs) { if (schema._invalids) { if (schema._invalids.has(value, state, prefs, schema._flags.insensitive)) { - const report = schema.createError(value === '' ? 'any.empty' : 'any.invalid', value, { invalids: schema._invalids.values({ stripUndefined: true }) }, state, prefs); + const report = schema.createError('any.invalid', value, { invalids: schema._invalids.values({ stripUndefined: true }) }, state, prefs); if (prefs.abortEarly) { return internals.finalize(value, schema, original, [report], state, prefs); } @@ -400,20 +362,16 @@ internals.finalize = function (value, schema, original, errors, state, prefs) { internals.prefs = function (schema, prefs) { - if (schema._preferences) { - const isDefaultOptions = prefs === Common.defaults; - if (isDefaultOptions && - schema._preferences[Common.symbols.prefs]) { + const isDefaultOptions = prefs === Common.defaults; + if (isDefaultOptions && + schema._preferences[Common.symbols.prefs]) { - return schema._preferences[Common.symbols.prefs]; - } - - prefs = Common.preferences(prefs, schema._preferences); - if (isDefaultOptions) { - schema._preferences[Common.symbols.prefs] = prefs; - } + return schema._preferences[Common.symbols.prefs]; + } - return prefs; + prefs = Common.preferences(prefs, schema._preferences); + if (isDefaultOptions) { + schema._preferences[Common.symbols.prefs] = prefs; } return prefs; @@ -468,13 +426,13 @@ internals.trim = function (value, schema) { } const trim = schema._uniqueRules.get('trim'); - if (trim && - trim.args.enabled) { + if (!trim || + !trim.args.enabled) { - value = value.trim(); + return value; } - return value; + return value.trim(); }; @@ -506,6 +464,50 @@ internals.Promise = class { }; +internals.externals = function (externals, outcome, prefs) { + + return new Promise(async (resolve, reject) => { + + let root = outcome.value; + + for (const { method, path, label } of externals) { + let value = root; + let key; + let parent; + + if (path.length) { + key = path[path.length - 1]; + parent = Hoek.reach(root, path.slice(0, -1)); + value = parent[key]; + } + + try { + var result = await method(value); + } + catch (err) { + err.message += ` (${label})`; + return reject(err); // Change message to include path + } + + if (result === undefined || + result === value) { + + continue; + } + + if (parent) { + parent[key] = result; + } + else { + root = result; + } + } + + resolve(prefs.warnings ? Object.assign(outcome, { value: root }) : root); + }); +}; + + internals.Shadow = class { constructor() { diff --git a/lib/values.js b/lib/values.js index 3bd528487..1018a1f94 100755 --- a/lib/values.js +++ b/lib/values.js @@ -11,7 +11,7 @@ module.exports = internals.Values = class { constructor(from) { this._set = new Set(from); - this._hasRef = false; + this._resolve = false; } get length() { @@ -21,11 +21,8 @@ module.exports = internals.Values = class { add(value, refs) { - const isRef = Common.isResolvable(value); - if (!isRef && - this.has(value, null, null, false)) { - - return this; + if (this.has(value, null, null, false)) { + return; } if (refs !== undefined) { // If it's a merge, we don't have any refs @@ -34,11 +31,9 @@ module.exports = internals.Values = class { this._set.add(value); - if (isRef) { - this._hasRef = true; + if (Common.isResolvable(value)) { + this._resolve = true; } - - return this; } static merge(target, add, remove) { @@ -63,7 +58,6 @@ module.exports = internals.Values = class { remove(value) { this._set.delete(value); - return this; } has(value, state, prefs, insensitive) { @@ -82,10 +76,17 @@ module.exports = internals.Values = class { return { value }; } + if (!this._resolve && + !insensitive && + typeof value !== 'object') { + + return false; + } + const extendedCheck = internals.extendedCheckForValue(value, insensitive); if (!extendedCheck) { if (state && - this._hasRef) { + this._resolve) { for (let item of this._set) { if (Common.isResolvable(item)) { @@ -106,7 +107,7 @@ module.exports = internals.Values = class { _has(value, state, prefs, check) { - const checkRef = !!(state && this._hasRef); + const checkRef = !!(state && this._resolve); const isReallyEqual = function (item) { @@ -167,14 +168,14 @@ module.exports = internals.Values = class { clone() { const set = new internals.Values(this._set); - set._hasRef = this._hasRef; + set._resolve = this._resolve; return set; } concat(source) { const set = new internals.Values([...this._set, ...source._set]); - set._hasRef = this._hasRef || source._hasRef; + set._resolve = this._resolve || source._resolve; return set; } diff --git a/test/errors.js b/test/errors.js index 8030e873b..c162b379f 100755 --- a/test/errors.js +++ b/test/errors.js @@ -51,7 +51,7 @@ describe('errors', () => { }; const messages = { - 'any.empty': '"{#label}" 3', + 'string.empty': '"{#label}" 3', 'date.base': '"{#label}" 18', 'string.base': '"{#label}" 13', 'string.min': '"{#label}" 14', @@ -121,8 +121,8 @@ describe('errors', () => { { message: '"notEmpty" 3', path: ['notEmpty'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'notEmpty', key: 'notEmpty' } + type: 'string.empty', + context: { value: '', label: 'notEmpty', key: 'notEmpty' } }, { message: '"value" 7', diff --git a/test/index.js b/test/index.js index 23c8b67db..cca66daa9 100755 --- a/test/index.js +++ b/test/index.js @@ -552,8 +552,8 @@ describe('Joi', () => { details: [{ message: '"upc" is not allowed to be empty', path: ['upc'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'upc', key: 'upc' } + type: 'string.empty', + context: { value: '', label: 'upc', key: 'upc' } }] }], [{ txt: 'test', upc: undefined }, false, null, { @@ -616,8 +616,8 @@ describe('Joi', () => { details: [{ message: '"upc" is not allowed to be empty', path: ['upc'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'upc', key: 'upc' } + type: 'string.empty', + context: { value: '', label: 'upc', key: 'upc' } }] }], [{ txt: 'test', upc: undefined }, true], @@ -696,8 +696,8 @@ describe('Joi', () => { details: [{ message: '"upc" is not allowed to be empty', path: ['upc'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'upc', key: 'upc' } + type: 'string.empty', + context: { value: '', label: 'upc', key: 'upc' } }] }], [{ txt: '', upc: 'test' }, false, null, { @@ -705,8 +705,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: null, upc: 'test' }, false, null, { @@ -725,8 +725,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: '' }, false, null, { @@ -734,8 +734,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: 'test', upc: 'test' }, false, null, { @@ -924,8 +924,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: null, upc: 'test' }, false, null, { @@ -946,8 +946,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: undefined, code: 999 }, false, null, { @@ -955,8 +955,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: undefined, code: undefined }, false, null, { @@ -964,8 +964,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: '' }, false, null, { @@ -973,8 +973,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: 'test', upc: 'test' }, true], @@ -1127,8 +1127,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: null, upc: 'test' }, false, null, { @@ -1209,8 +1209,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: undefined, code: 999 }, false, null, { @@ -1218,8 +1218,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: undefined, code: undefined }, false, null, { @@ -1227,8 +1227,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: '', upc: '' }, false, null, { @@ -1236,8 +1236,8 @@ describe('Joi', () => { details: [{ message: '"txt" is not allowed to be empty', path: ['txt'], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'txt', key: 'txt' } + type: 'string.empty', + context: { value: '', label: 'txt', key: 'txt' } }] }], [{ txt: 'test', upc: 'test' }, false, null, { diff --git a/test/types/any.js b/test/types/any.js index 0d7bee585..07f60b71e 100755 --- a/test/types/any.js +++ b/test/types/any.js @@ -153,7 +153,7 @@ describe('any', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'a', invalids: ['', 'a'], label: 'value' } + context: { value: 'a', invalids: ['a'], label: 'value' } }] }] ]); @@ -178,7 +178,7 @@ describe('any', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'a', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'a', invalids: ['a', 'b'], label: 'value' } }] }], ['b', false, null, { @@ -187,7 +187,7 @@ describe('any', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'b', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'b', invalids: ['a', 'b'], label: 'value' } }] }] ]); @@ -412,15 +412,7 @@ describe('any', () => { context: { value: 'b', valids: ['a'], label: 'value' } }] }], - ['', false, null, { - message: '"value" must be one of [a]', - details: [{ - message: '"value" must be one of [a]', - path: [], - type: 'any.only', - context: { value: '', valids: ['a'], label: 'value' } - }] - }], + ['', true, null, undefined], [' ', true, null, undefined] ]); @@ -431,7 +423,7 @@ describe('any', () => { empty: { type: 'string', flags: { only: true }, - allow: [' '] + allow: ['', ' '] }, insensitive: true }, @@ -1263,8 +1255,8 @@ describe('any', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], ['def', true, null, 'def'] @@ -1282,8 +1274,8 @@ describe('any', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }] ]); @@ -1300,8 +1292,8 @@ describe('any', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }] ]); @@ -1795,8 +1787,7 @@ describe('any', () => { it('does not leak into sub objects', async () => { const schema = Joi.object({ a: Joi.number() }).label('foo'); - const err = await expect(schema.validate({ a: 'a' })).to.reject(); - expect(err.message).to.equal('"a" must be a number'); + const err = await expect(schema.validate({ a: 'a' })).to.reject('"a" must be a number'); expect(err.details).to.equal([{ message: '"a" must be a number', path: ['a'], @@ -1811,9 +1802,7 @@ describe('any', () => { Joi.object({ a: Joi.number() }).label('foo') ).label('bar'); - const err = await expect(schema.validate([{ a: 'a' }])).to.reject(); - expect(err).to.exist(); - expect(err.message).to.equal('"[0].a" must be a number'); + const err = await expect(schema.validate([{ a: 'a' }])).to.reject('"[0].a" must be a number'); expect(err.details).to.equal([{ message: '"[0].a" must be a number', path: [0, 'a'], @@ -1825,9 +1814,7 @@ describe('any', () => { it('does not leak into unknown keys', async () => { const schema = Joi.object({ a: Joi.number() }).label('foo'); - const err = await expect(schema.validate({ b: 'a' })).to.reject(); - expect(err).to.exist(); - expect(err.message).to.equal('"b" is not allowed'); + const err = await expect(schema.validate({ b: 'a' })).to.reject('"b" is not allowed'); expect(err.details).to.equal([{ message: '"b" is not allowed', path: ['b'], diff --git a/test/types/string.js b/test/types/string.js index 81aa64731..8c34580e1 100755 --- a/test/types/string.js +++ b/test/types/string.js @@ -30,6 +30,13 @@ describe('string', () => { expect(() => Joi.string('invalid argument.')).to.throw('The string type does not allow arguments'); }); + it('blocks empty strings by default', async () => { + + await expect(Joi.string().validate('')).to.reject('"value" is not allowed to be empty'); + await expect(Joi.string().allow('x').validate('')).to.reject('"value" is not allowed to be empty'); + await expect(Joi.string().allow('').validate('')).to.not.reject(); + }); + it('fails on boolean', () => { const schema = Joi.string(); @@ -187,7 +194,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'a', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'a', invalids: ['a', 'b'], label: 'value' } }] }], ['b', false, null, { @@ -196,7 +203,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'b', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'b', invalids: ['a', 'b'], label: 'value' } }] }], ['A', true], @@ -213,7 +220,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'a', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'a', invalids: ['a', 'b'], label: 'value' } }] }], ['b', false, null, { @@ -222,7 +229,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'b', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'b', invalids: ['a', 'b'], label: 'value' } }] }], ['A', false, null, { @@ -231,7 +238,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'A', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'A', invalids: ['a', 'b'], label: 'value' } }] }], ['B', false, null, { @@ -240,7 +247,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'B', invalids: ['', 'a', 'b'], label: 'value' } + context: { value: 'B', invalids: ['a', 'b'], label: 'value' } }] }] ]); @@ -2791,8 +2798,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], ['(╯°□°)╯︵ ┻━┻', false, null, { @@ -3246,8 +3253,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], ['(╯°□°)╯︵ ┻━┻', false, null, { @@ -4391,8 +4398,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], ['(╯°□°)╯︵ ┻━┻', false, null, { @@ -4543,8 +4550,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }] ]); @@ -4567,8 +4574,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }] ]); @@ -4581,8 +4588,8 @@ describe('string', () => { expect(err.details).to.equal([{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }]); }); @@ -4594,8 +4601,8 @@ describe('string', () => { expect(err.details).to.equal([{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }]); }); @@ -4628,7 +4635,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'a', invalids: ['', 'a', 'b', 'c'], label: 'value' } + context: { value: 'a', invalids: ['a', 'b', 'c'], label: 'value' } }] }], ['c', false, null, { @@ -4637,7 +4644,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'c', invalids: ['', 'a', 'b', 'c'], label: 'value' } + context: { value: 'c', invalids: ['a', 'b', 'c'], label: 'value' } }] }] ]); @@ -4988,8 +4995,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5029,8 +5036,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5136,8 +5143,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, true] @@ -5183,8 +5190,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5285,8 +5292,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5382,8 +5389,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5568,8 +5575,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5648,8 +5655,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5800,8 +5807,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -5907,8 +5914,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6014,8 +6021,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6153,8 +6160,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6208,8 +6215,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6248,7 +6255,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: '123@x.com', invalids: ['', '123@x.com'], label: 'value' } + context: { value: '123@x.com', invalids: ['123@x.com'], label: 'value' } }] }], ['1234@x.com', true], @@ -6271,8 +6278,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', '123@x.com'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6313,8 +6320,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6340,7 +6347,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: '123@x.com', invalids: ['', '123@x.com'], label: 'value' } + context: { value: '123@x.com', invalids: ['123@x.com'], label: 'value' } }] }], ['1234@x.com', true], @@ -6363,8 +6370,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', '123@x.com'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6466,7 +6473,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: '123@x.com', invalids: ['', '123@x.com'], label: 'value' } + context: { value: '123@x.com', invalids: ['123@x.com'], label: 'value' } }] }], ['1234@x.com', true], @@ -6489,8 +6496,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', '123@x.com'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6646,8 +6653,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -6774,8 +6781,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -7168,8 +7175,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -7358,8 +7365,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -7483,7 +7490,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: '2013-06-07T14:21+07:00', invalids: ['', '2013-06-07T14:21+07:00'], label: 'value' } + context: { value: '2013-06-07T14:21+07:00', invalids: ['2013-06-07T14:21+07:00'], label: 'value' } }] }], ['2013-06-07T14:21+07:000', false, null, { @@ -7556,8 +7563,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', '2013-06-07T14:21+07:00'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -7733,8 +7740,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -7845,7 +7852,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: '2013-06-07T14:21+07:00', invalids: ['', '2013-06-07T14:21+07:00'], label: 'value' } + context: { value: '2013-06-07T14:21+07:00', invalids: ['2013-06-07T14:21+07:00'], label: 'value' } }] }], ['2013-06-07T14:21+07:000', false, null, { @@ -7918,8 +7925,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', '2013-06-07T14:21+07:00'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -8375,7 +8382,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: '2013-06-07T14:21Z', invalids: ['', '2013-06-07T14:21Z'], label: 'value' } + context: { value: '2013-06-07T14:21Z', invalids: ['2013-06-07T14:21Z'], label: 'value' } }] }], ['2013-06-07T14:21+07:00', false, null, { @@ -8475,8 +8482,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', '2013-06-07T14:21Z'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -9076,8 +9083,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -9501,8 +9508,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -9583,8 +9590,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -11444,8 +11451,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -11565,8 +11572,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -11650,7 +11657,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'b4b2fb69c6244e5eb0698e0c6ec66618', invalids: ['', 'b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } + context: { value: 'b4b2fb69c6244e5eb0698e0c6ec66618', invalids: ['b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } }] }], ['{283B67B2-430F-4E6F-97E6-19041992-C1B0}', false, null, { @@ -11694,8 +11701,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', 'b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -11804,8 +11811,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -11889,7 +11896,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'b4b2fb69c6244e5eb0698e0c6ec66618', invalids: ['', 'b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } + context: { value: 'b4b2fb69c6244e5eb0698e0c6ec66618', invalids: ['b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } }] }], ['{283B67B2-430F-4E6F-97E6-19041992-C1B0}', false, null, { @@ -11922,8 +11929,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', 'b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -12245,7 +12252,7 @@ describe('string', () => { message: '"value" contains an invalid value', path: [], type: 'any.invalid', - context: { value: 'b4b2fb69c6244e5eb0698e0c6ec66618', invalids: ['', 'b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } + context: { value: 'b4b2fb69c6244e5eb0698e0c6ec66618', invalids: ['b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } }] }], ['{283B67B2-430F-4E6F-97E6-19041992-C1B0}', false, null, { @@ -12278,8 +12285,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: ['', 'b4b2fb69c6244e5eb0698e0c6ec66618'], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -12687,8 +12694,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { @@ -12999,8 +13006,8 @@ describe('string', () => { details: [{ message: '"value" is not allowed to be empty', path: [], - type: 'any.empty', - context: { value: '', invalids: [''], label: 'value' } + type: 'string.empty', + context: { value: '', label: 'value' } }] }], [null, false, null, { diff --git a/test/values.js b/test/values.js index e53d196b6..305c5b1fe 100755 --- a/test/values.js +++ b/test/values.js @@ -158,7 +158,7 @@ describe('Values', () => { const set = new Values(); set.add(Joi.ref('x')); set.concat(new Values()); - expect(set._hasRef).to.be.true(); + expect(set._resolve).to.be.true(); }); }); });