mirror of https://gitee.com/bigwinds/arangodb
Updated joi to 6.0.8.
This commit is contained in:
parent
e7a7ae2abd
commit
13c3cb9a5e
|
@ -47,6 +47,9 @@ v2.6.0 (XXXX-XX-XX)
|
|||
|
||||
* added `scripts` property to Foxx manifests. You should now specify the `setup` and `teardown` files as properties of the `scripts` object in your manifests.
|
||||
|
||||
* updated `joi` package to 6.0.8.
|
||||
|
||||
|
||||
v2.5.2 (XXXX-XX-XX)
|
||||
-------------------
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
examples
|
|
@ -9,7 +9,6 @@ language: node_js
|
|||
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
- iojs
|
||||
|
||||
|
|
|
@ -17,16 +17,16 @@ var schema = Joi.object().keys({
|
|||
.when('q2', { is: true, then: Joi.valid('1-5', '6-10', '11-50', '50+').required() }),
|
||||
// Rate 20% of most friendly Parisians, from how many people you know answered in q3, individually on 1-5 rating
|
||||
q4: Joi.array()
|
||||
.when('q3', {is: '1-5', then: Joi.array().min(0).max(1).includes(intRating).required() })
|
||||
.when('q3', {is: '6-10', then: Joi.array().min(1).max(2).includes(intRating).required() })
|
||||
.when('q3', {is: '11-50', then: Joi.array().min(2).max(10).includes(intRating).required() })
|
||||
.when('q3', {is: '50+' , then: Joi.array().min(10).includes(intRating).required() }),
|
||||
.when('q3', {is: '1-5', then: Joi.array().min(0).max(1).items(intRating).required() })
|
||||
.when('q3', {is: '6-10', then: Joi.array().min(1).max(2).items(intRating).required() })
|
||||
.when('q3', {is: '11-50', then: Joi.array().min(2).max(10).items(intRating).required() })
|
||||
.when('q3', {is: '50+', then: Joi.array().min(10).items(intRating).required() }),
|
||||
// Rate remaining 80% of Parisians, from how many people you know answered in q3, individually on 1-5 rating
|
||||
q5: Joi.array()
|
||||
.when('q3', {is: '1-5', then: Joi.array().min(1).max(4).includes(intRating).required() })
|
||||
.when('q3', {is: '6-10', then: Joi.array().min(4).max(8).includes(intRating).required() })
|
||||
.when('q3', {is: '11-50', then: Joi.array().min(8).max(40).includes(intRating).required() })
|
||||
.when('q3', {is: '50+' , then: Joi.array().min(40).includes(intRating).required().required() }),
|
||||
.when('q3', {is: '1-5', then: Joi.array().min(1).max(4).items(intRating).required() })
|
||||
.when('q3', {is: '6-10', then: Joi.array().min(4).max(8).items(intRating).required() })
|
||||
.when('q3', {is: '11-50', then: Joi.array().min(8).max(40).items(intRating).required() })
|
||||
.when('q3', {is: '50+', then: Joi.array().min(40).items(intRating).required().required() }),
|
||||
// Rate the reputation of Parisians in general, 1-5 rating
|
||||
q6: intRating.required()
|
||||
});
|
||||
|
@ -36,7 +36,7 @@ var response = {
|
|||
q2: true,
|
||||
q3: '1-5',
|
||||
q4: [5],
|
||||
q4: [1],
|
||||
q5: [1],
|
||||
q6: 2
|
||||
};
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ internals.Alternatives.prototype.try = function (/* schemas */) {
|
|||
for (var i = 0, il = schemas.length; i < il; ++i) {
|
||||
var cast = Cast.schema(schemas[i]);
|
||||
if (cast._refs.length) {
|
||||
obj._refs = obj._refs.concat(cast._refs)
|
||||
obj._refs = obj._refs.concat(cast._refs);
|
||||
}
|
||||
obj._inner.matches.push({ schema: cast });
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ internals.Any.prototype.concat = function (schema) {
|
|||
keys[target[k].key] = k;
|
||||
}
|
||||
|
||||
for (k = 0, kl = source.length; k < kl; ++k) {
|
||||
for (k = 0, kl = source.length; k < kl; ++k) {
|
||||
var sourceKey = source[k].key;
|
||||
if (keys[sourceKey] >= 0) {
|
||||
target[keys[sourceKey]] = {
|
||||
|
@ -264,7 +264,7 @@ internals.Any.prototype.invalid = internals.Any.prototype.disallow = internals.A
|
|||
var obj = this.clone();
|
||||
var values = Hoek.flatten(Array.prototype.slice.call(arguments));
|
||||
for (var i = 0, il = values.length; i < il; ++i) {
|
||||
var value = values[i];
|
||||
value = values[i];
|
||||
obj._valids.remove(value);
|
||||
obj._invalids.add(value, this._refs);
|
||||
}
|
||||
|
@ -797,12 +797,12 @@ internals.concatSettings = function (target, source) {
|
|||
return null;
|
||||
}
|
||||
|
||||
var obj = {};
|
||||
var key, obj = {};
|
||||
|
||||
if (target) {
|
||||
var tKeys = Object.keys(target);
|
||||
for (var i = 0, il = tKeys.length; i < il; ++i) {
|
||||
var key = tKeys[i];
|
||||
key = tKeys[i];
|
||||
obj[key] = target[key];
|
||||
}
|
||||
}
|
||||
|
@ -810,7 +810,7 @@ internals.concatSettings = function (target, source) {
|
|||
if (source) {
|
||||
var sKeys = Object.keys(source);
|
||||
for (var j = 0, jl = sKeys.length; j < jl; ++j) {
|
||||
var key = sKeys[j];
|
||||
key = sKeys[j];
|
||||
if (key !== 'language' ||
|
||||
!obj.hasOwnProperty(key)) {
|
||||
|
||||
|
|
|
@ -396,7 +396,7 @@ internals.Array.prototype.single = function (enabled) {
|
|||
var obj = this.clone();
|
||||
obj._flags.single = enabled === undefined ? true : !!enabled;
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = new internals.Array();
|
||||
|
|
|
@ -95,7 +95,7 @@ internals.compare = function (type, compare) {
|
|||
var isRef = Ref.isRef(date);
|
||||
|
||||
if (!isNow && !isRef) {
|
||||
date = internals.toDate(date);
|
||||
date = internals.toDate(date);
|
||||
}
|
||||
|
||||
Hoek.assert(date, 'Invalid date format');
|
||||
|
|
|
@ -162,6 +162,52 @@ internals.getPath = function (item) {
|
|||
};
|
||||
|
||||
|
||||
// Inspired by json-stringify-safe
|
||||
internals.safeStringify = function (obj, spaces) {
|
||||
|
||||
return JSON.stringify(obj, internals.serializer(), spaces);
|
||||
};
|
||||
|
||||
internals.serializer = function () {
|
||||
|
||||
var cycleReplacer = function (key, value) {
|
||||
|
||||
if (stack[0] === value) {
|
||||
return '[Circular ~]';
|
||||
}
|
||||
|
||||
return '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']';
|
||||
};
|
||||
|
||||
var keys = [], stack = [];
|
||||
|
||||
return function (key, value) {
|
||||
|
||||
if (stack.length > 0) {
|
||||
var thisPos = stack.indexOf(this);
|
||||
if (~thisPos) {
|
||||
stack.length = thisPos + 1;
|
||||
keys.length = thisPos + 1;
|
||||
keys[thisPos] = key;
|
||||
}
|
||||
else {
|
||||
stack.push(this);
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
if (~stack.indexOf(value)) {
|
||||
value = cycleReplacer.call(this, key, value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
stack.push(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
internals.annotate = function () {
|
||||
|
||||
var obj = Hoek.clone(this._object || {});
|
||||
|
@ -200,17 +246,17 @@ internals.annotate = function () {
|
|||
}
|
||||
}
|
||||
|
||||
var annotated = JSON.stringify(obj, null, 2);
|
||||
var message = internals.safeStringify(obj, 2)
|
||||
.replace(/\[Circular (.*?)_\$key\$_([, \d]+)_\$end\$_\]/g, function ($0, $1) {
|
||||
|
||||
annotated = annotated.replace(/_\$key\$_([, \d]+)_\$end\$_\"/g, function ($0, $1) {
|
||||
return '[Circular ' + $1 + ']';
|
||||
}).replace(/_\$key\$_([, \d]+)_\$end\$_\"/g, function ($0, $1) {
|
||||
|
||||
return '" \u001b[31m[' + $1 + ']\u001b[0m';
|
||||
});
|
||||
return '" \u001b[31m[' + $1 + ']\u001b[0m';
|
||||
}).replace(/\"_\$miss\$_([^\|]+)\|(\d+)_\$end\$_\"\: \"__missing__\"/g, function ($0, $1, $2) {
|
||||
|
||||
var message = annotated.replace(/\"_\$miss\$_([^\|]+)\|(\d+)_\$end\$_\"\: \"__missing__\"/g, function ($0, $1, $2) {
|
||||
|
||||
return '\u001b[41m"' + $1 + '"\u001b[0m\u001b[31m [' + $2 + ']: -- missing --\u001b[0m';
|
||||
});
|
||||
return '\u001b[41m"' + $1 + '"\u001b[0m\u001b[31m [' + $2 + ']: -- missing --\u001b[0m';
|
||||
});
|
||||
|
||||
message += '\n\u001b[31m';
|
||||
|
||||
|
@ -222,4 +268,3 @@ internals.annotate = function () {
|
|||
|
||||
return message;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,10 +10,184 @@ var Errors = require('./errors');
|
|||
// Declare internals
|
||||
|
||||
var internals = {
|
||||
uriRegex: createUriRegex(),
|
||||
createUriRegex: createUriRegex
|
||||
createUriRegex: function (optionalScheme) {
|
||||
/**
|
||||
* DIGIT = %x30-39 ; 0-9
|
||||
*/
|
||||
var digit = '0-9',
|
||||
digitOnly = '[' + digit + ']';
|
||||
|
||||
/**
|
||||
* ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
|
||||
*/
|
||||
var alpha = 'a-zA-Z',
|
||||
alphaOnly = '[' + alpha + ']';
|
||||
|
||||
/**
|
||||
* HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
|
||||
*/
|
||||
var hexDigit = digit + 'A-Fa-f',
|
||||
hexDigitOnly = '[' + hexDigit + ']';
|
||||
|
||||
/**
|
||||
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
*/
|
||||
var unreserved = alpha + digit + '-\\._~';
|
||||
|
||||
/**
|
||||
* pct-encoded = "%" HEXDIG HEXDIG
|
||||
*/
|
||||
var pctEncoded = '%' + hexDigit;
|
||||
|
||||
/**
|
||||
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
||||
*/
|
||||
var subDelims = '!\\$&\'\\(\\)\\*\\+,;=';
|
||||
|
||||
/**
|
||||
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
*/
|
||||
var pchar = unreserved + pctEncoded + subDelims + ':@',
|
||||
pcharOnly = '[' + pchar + ']';
|
||||
|
||||
/**
|
||||
* elements separated by forward slash ("/") are alternatives.
|
||||
*/
|
||||
var or = '|';
|
||||
|
||||
/**
|
||||
* Rule to support zero-padded addresses.
|
||||
*/
|
||||
var zeroPad = '0?';
|
||||
|
||||
/**
|
||||
* dec-octet = DIGIT ; 0-9
|
||||
* / %x31-39 DIGIT ; 10-99
|
||||
* / "1" 2DIGIT ; 100-199
|
||||
* / "2" %x30-34 DIGIT ; 200-249
|
||||
* / "25" %x30-35 ; 250-255
|
||||
*/
|
||||
var decOctect = '(?:' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + digitOnly + digitOnly + or + '2' + '[0-4]' + digitOnly + or + '25' + '[0-5])';
|
||||
|
||||
/**
|
||||
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
||||
*/
|
||||
var scheme = alphaOnly + '[' + alpha + digit + '+-\\.]*';
|
||||
|
||||
// If we were passed a scheme, use it instead of the generic one
|
||||
if (optionalScheme) {
|
||||
// Have to put this in a non-capturing group to handle the OR statements
|
||||
scheme = '(?:' + optionalScheme + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
|
||||
*/
|
||||
var userinfo = '[' + unreserved + pctEncoded + subDelims + ':]*';
|
||||
|
||||
/**
|
||||
* IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
|
||||
*/
|
||||
var IPv4address = '(?:' + decOctect + '\\.){3}' + decOctect;
|
||||
|
||||
/**
|
||||
* h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal
|
||||
* ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address
|
||||
* IPv6address = 6( h16 ":" ) ls32
|
||||
* / "::" 5( h16 ":" ) ls32
|
||||
* / [ h16 ] "::" 4( h16 ":" ) ls32
|
||||
* / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
|
||||
* / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
|
||||
* / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
|
||||
* / [ *4( h16 ":" ) h16 ] "::" ls32
|
||||
* / [ *5( h16 ":" ) h16 ] "::" h16
|
||||
* / [ *6( h16 ":" ) h16 ] "::"
|
||||
*/
|
||||
var h16 = hexDigitOnly + '{1,4}',
|
||||
ls32 = '(?:' + h16 + ':' + h16 + '|' + IPv4address + ')',
|
||||
IPv6SixHex = '(?:' + h16 + ':){6}' + ls32,
|
||||
IPv6FiveHex = '::(?:' + h16 + ':){5}' + ls32,
|
||||
IPv6FourHex = h16 + '::(?:' + h16 + ':){4}' + ls32,
|
||||
IPv6ThreeeHex = '(?:' + h16 + ':){0,1}' + h16 + '::(?:' + h16 + ':){3}' + ls32,
|
||||
IPv6TwoHex = '(?:' + h16 + ':){0,2}' + h16 + '::(?:' + h16 + ':){2}' + ls32,
|
||||
IPv6OneHex = '(?:' + h16 + ':){0,3}' + h16 + '::' + h16 + ':' + ls32,
|
||||
IPv6NoneHex = '(?:' + h16 + ':){0,4}' + h16 + '::' + ls32,
|
||||
IPv6NoneHex2 = '(?:' + h16 + ':){0,5}' + h16 + '::' + h16,
|
||||
IPv6NoneHex3 = '(?:' + h16 + ':){0,6}' + h16 + '::',
|
||||
IPv6address = '(?:' + IPv6SixHex + or + IPv6FiveHex + or + IPv6FourHex + or + IPv6ThreeeHex + or + IPv6TwoHex + or + IPv6OneHex + or + IPv6NoneHex + or + IPv6NoneHex2 + or + IPv6NoneHex3 + ')';
|
||||
|
||||
/**
|
||||
* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
|
||||
*/
|
||||
var IPvFuture = 'v' + hexDigitOnly + '+\\.[' + unreserved + subDelims + ':]+';
|
||||
|
||||
/**
|
||||
* IP-literal = "[" ( IPv6address / IPvFuture ) "]"
|
||||
*/
|
||||
var IPLiteral = '\\[(?:' + IPv6address + or + IPvFuture + ')\\]';
|
||||
|
||||
/**
|
||||
* reg-name = *( unreserved / pct-encoded / sub-delims )
|
||||
*/
|
||||
var regName = '[' + unreserved + pctEncoded + subDelims + ']{0,255}';
|
||||
|
||||
/**
|
||||
* host = IP-literal / IPv4address / reg-name
|
||||
*/
|
||||
var host = '(?:' + IPLiteral + or + IPv4address + or + regName + ')';
|
||||
|
||||
/**
|
||||
* port = *DIGIT
|
||||
*/
|
||||
var port = digitOnly + '*';
|
||||
|
||||
/**
|
||||
* authority = [ userinfo "@" ] host [ ":" port ]
|
||||
*/
|
||||
var authority = '(?:' + userinfo + '@)?' + host + '(?::' + port + ')?';
|
||||
|
||||
/**
|
||||
* segment = *pchar
|
||||
* segment-nz = 1*pchar
|
||||
* path = path-abempty ; begins with "/" or is empty
|
||||
* / path-absolute ; begins with "/" but not "//"
|
||||
* / path-noscheme ; begins with a non-colon segment
|
||||
* / path-rootless ; begins with a segment
|
||||
* / path-empty ; zero characters
|
||||
* path-abempty = *( "/" segment )
|
||||
* path-absolute = "/" [ segment-nz *( "/" segment ) ]
|
||||
* path-rootless = segment-nz *( "/" segment )
|
||||
*/
|
||||
var segment = pcharOnly + '*',
|
||||
segmentNz = pcharOnly + '+',
|
||||
pathAbEmpty = '(?:\\/' + segment + ')*',
|
||||
pathAbsolute = '\\/(?:' + segmentNz + pathAbEmpty + ')?',
|
||||
pathRootless = segmentNz + pathAbEmpty;
|
||||
|
||||
/**
|
||||
* hier-part = "//" authority path
|
||||
*/
|
||||
var hierPart = '(?:\\/\\/' + authority + pathAbEmpty + or + pathAbsolute + or + pathRootless + ')';
|
||||
|
||||
/**
|
||||
* query = *( pchar / "/" / "?" )
|
||||
*/
|
||||
var query = '[' + pchar + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line.
|
||||
|
||||
/**
|
||||
* fragment = *( pchar / "/" / "?" )
|
||||
*/
|
||||
var fragment = '[' + pchar + '\\/\\?]*';
|
||||
|
||||
/**
|
||||
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
||||
*/
|
||||
return new RegExp('^' + scheme + ':' + hierPart + '(?:\\?' + query + ')?' + '(?:#' + fragment + ')?$');
|
||||
}
|
||||
};
|
||||
|
||||
internals.uriRegex = internals.createUriRegex();
|
||||
|
||||
|
||||
internals.String = function () {
|
||||
|
||||
|
@ -102,7 +276,7 @@ internals.String.prototype.creditCard = function () {
|
|||
mul ^= 3;
|
||||
}
|
||||
|
||||
var check = (sum % 10 === 0) && (sum > 0);
|
||||
var check = (sum % 10 === 0) && (sum > 0);
|
||||
return check ? null : Errors.create('string.creditCard', { value: value }, state, options);
|
||||
});
|
||||
};
|
||||
|
@ -199,8 +373,8 @@ internals.String.prototype.email = function (isEmailOptions) {
|
|||
|
||||
|
||||
internals.String.prototype.uri = function (uriOptions) {
|
||||
var regex = internals.uriRegex,
|
||||
customScheme;
|
||||
var customScheme,
|
||||
regex = internals.uriRegex;
|
||||
|
||||
if (uriOptions) {
|
||||
Hoek.assert(typeof uriOptions === 'object', 'uri options must be an object');
|
||||
|
@ -224,10 +398,9 @@ internals.String.prototype.uri = function (uriOptions) {
|
|||
if (scheme instanceof RegExp) {
|
||||
return accumulator + scheme.source;
|
||||
}
|
||||
else {
|
||||
Hoek.assert(/[a-zA-Z][a-zA-Z0-9+-\.]*/.test(scheme), 'scheme at position ' + index + ' must be a valid scheme');
|
||||
return accumulator + Hoek.escapeRegex(scheme);
|
||||
}
|
||||
|
||||
Hoek.assert(/[a-zA-Z][a-zA-Z0-9+-\.]*/.test(scheme), 'scheme at position ' + index + ' must be a valid scheme');
|
||||
return accumulator + Hoek.escapeRegex(scheme);
|
||||
}, '');
|
||||
}
|
||||
}
|
||||
|
@ -307,7 +480,7 @@ internals.String.prototype.hostname = function () {
|
|||
return null;
|
||||
}
|
||||
|
||||
return Errors.create("string.hostname", { value: value }, state, options);
|
||||
return Errors.create('string.hostname', { value: value }, state, options);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -365,179 +538,4 @@ internals.String.prototype.trim = function () {
|
|||
return obj;
|
||||
};
|
||||
|
||||
function createUriRegex (optionalScheme) {
|
||||
/**
|
||||
* DIGIT = %x30-39 ; 0-9
|
||||
*/
|
||||
var digit = '0-9',
|
||||
digitOnly = '[' + digit + ']';
|
||||
|
||||
/**
|
||||
* ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
|
||||
*/
|
||||
var alpha = 'a-zA-Z',
|
||||
alphaOnly = '[' + alpha + ']';
|
||||
|
||||
/**
|
||||
* HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
|
||||
*/
|
||||
var hexDigit = digit + 'A-Fa-f',
|
||||
hexDigitOnly = '[' + hexDigit + ']';
|
||||
|
||||
/**
|
||||
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
*/
|
||||
var unreserved = alpha + digit + '-\\._~';
|
||||
|
||||
/**
|
||||
* pct-encoded = "%" HEXDIG HEXDIG
|
||||
*/
|
||||
var pctEncoded = '%' + hexDigit;
|
||||
|
||||
/**
|
||||
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
||||
*/
|
||||
var subDelims = '!\\$&\'\\(\\)\\*\\+,;=';
|
||||
|
||||
/**
|
||||
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
*/
|
||||
var pchar = unreserved + pctEncoded + subDelims + ':@',
|
||||
pcharOnly = '[' + pchar + ']';
|
||||
|
||||
/**
|
||||
* elements separated by forward slash ("/") are alternatives.
|
||||
*/
|
||||
var or = '|';
|
||||
|
||||
/**
|
||||
* Rule to support zero-padded addresses.
|
||||
*/
|
||||
var zeroPad = '0?';
|
||||
|
||||
/**
|
||||
* dec-octet = DIGIT ; 0-9
|
||||
* / %x31-39 DIGIT ; 10-99
|
||||
* / "1" 2DIGIT ; 100-199
|
||||
* / "2" %x30-34 DIGIT ; 200-249
|
||||
* / "25" %x30-35 ; 250-255
|
||||
*/
|
||||
var decOctect = '(?:' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + digitOnly + digitOnly + or + '2' + '[0-4]' + digitOnly + or + '25' + '[0-5])';
|
||||
|
||||
/**
|
||||
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
||||
*/
|
||||
var scheme = alphaOnly + '[' + alpha + digit + '+-\\.]*';
|
||||
|
||||
// If we were passed a scheme, use it instead of the generic one
|
||||
if (optionalScheme) {
|
||||
// Have to put this in a non-capturing group to handle the OR statements
|
||||
scheme = '(?:' + optionalScheme + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
|
||||
*/
|
||||
var userinfo = '[' + unreserved + pctEncoded + subDelims + ':]*';
|
||||
|
||||
/**
|
||||
* IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
|
||||
*/
|
||||
var IPv4address = '(?:' + decOctect + '\\.){3}' + decOctect;
|
||||
|
||||
/**
|
||||
* h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal
|
||||
* ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address
|
||||
* IPv6address = 6( h16 ":" ) ls32
|
||||
* / "::" 5( h16 ":" ) ls32
|
||||
* / [ h16 ] "::" 4( h16 ":" ) ls32
|
||||
* / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
|
||||
* / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
|
||||
* / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
|
||||
* / [ *4( h16 ":" ) h16 ] "::" ls32
|
||||
* / [ *5( h16 ":" ) h16 ] "::" h16
|
||||
* / [ *6( h16 ":" ) h16 ] "::"
|
||||
*/
|
||||
var h16 = hexDigitOnly + '{1,4}',
|
||||
ls32 = '(?:' + h16 + ':' + h16 + '|' + IPv4address + ')',
|
||||
IPv6SixHex = '(?:' + h16 + ':){6}' + ls32,
|
||||
IPv6FiveHex = '::(?:' + h16 + ':){5}' + ls32,
|
||||
IPv6FourHex = h16 + '::(?:' + h16 + ':){4}' + ls32,
|
||||
IPv6ThreeeHex = '(?:' + h16 + ':){0,1}' + h16 + '::(?:' + h16 + ':){3}' + ls32,
|
||||
IPv6TwoHex = '(?:' + h16 + ':){0,2}' + h16 + '::(?:' + h16 + ':){2}' + ls32,
|
||||
IPv6OneHex = '(?:' + h16 + ':){0,3}' + h16 + '::' + h16 + ':' + ls32,
|
||||
IPv6NoneHex = '(?:' + h16 + ':){0,4}' + h16 + '::' + ls32,
|
||||
IPv6NoneHex2 = '(?:' + h16 + ':){0,5}' + h16 + '::' + h16,
|
||||
IPv6NoneHex3 = '(?:' + h16 + ':){0,6}' + h16 + '::',
|
||||
IPv6address = '(?:' + IPv6SixHex + or + IPv6FiveHex + or + IPv6FourHex + or + IPv6ThreeeHex + or + IPv6TwoHex + or + IPv6OneHex + or + IPv6NoneHex + or + IPv6NoneHex2 + or + IPv6NoneHex3 + ')';
|
||||
|
||||
/**
|
||||
* IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
|
||||
*/
|
||||
var IPvFuture = 'v' + hexDigitOnly +'+\\.[' + unreserved + subDelims + ':]+';
|
||||
|
||||
/**
|
||||
* IP-literal = "[" ( IPv6address / IPvFuture ) "]"
|
||||
*/
|
||||
var IPLiteral = '\\[(?:' + IPv6address + or + IPvFuture + ')\\]';
|
||||
|
||||
/**
|
||||
* reg-name = *( unreserved / pct-encoded / sub-delims )
|
||||
*/
|
||||
var regName = '[' + unreserved + pctEncoded + subDelims + ']{0,255}';
|
||||
|
||||
/**
|
||||
* host = IP-literal / IPv4address / reg-name
|
||||
*/
|
||||
var host = '(?:' + IPLiteral + or + IPv4address + or + regName + ')';
|
||||
|
||||
/**
|
||||
* port = *DIGIT
|
||||
*/
|
||||
var port = digitOnly + '*';
|
||||
|
||||
/**
|
||||
* authority = [ userinfo "@" ] host [ ":" port ]
|
||||
*/
|
||||
var authority = '(?:' + userinfo + '@)?' + host + '(?::' + port + ')?';
|
||||
|
||||
/**
|
||||
* segment = *pchar
|
||||
* segment-nz = 1*pchar
|
||||
* path = path-abempty ; begins with "/" or is empty
|
||||
* / path-absolute ; begins with "/" but not "//"
|
||||
* / path-noscheme ; begins with a non-colon segment
|
||||
* / path-rootless ; begins with a segment
|
||||
* / path-empty ; zero characters
|
||||
* path-abempty = *( "/" segment )
|
||||
* path-absolute = "/" [ segment-nz *( "/" segment ) ]
|
||||
* path-rootless = segment-nz *( "/" segment )
|
||||
*/
|
||||
var segment = pcharOnly + '*',
|
||||
segmentNz = pcharOnly + '+',
|
||||
pathAbEmpty = '(?:\\/' + segment + ')*',
|
||||
pathAbsolute = '\\/(?:' + segmentNz + pathAbEmpty + ')?',
|
||||
pathRootless = segmentNz + pathAbEmpty;
|
||||
|
||||
/**
|
||||
* hier-part = "//" authority path
|
||||
*/
|
||||
var hierPart = '(?:\\/\\/' + authority + pathAbEmpty + or + pathAbsolute + or + pathRootless + ')';
|
||||
|
||||
/**
|
||||
* query = *( pchar / "/" / "?" )
|
||||
*/
|
||||
var query = '[' + pchar + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line.
|
||||
|
||||
/**
|
||||
* fragment = *( pchar / "/" / "?" )
|
||||
*/
|
||||
var fragment = '[' + pchar +'\\/\\?]*';
|
||||
|
||||
/**
|
||||
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
||||
*/
|
||||
return new RegExp('^' + scheme + ':' + hierPart + '(?:\\?' + query + ')?' + '(?:#' + fragment + ')?$');
|
||||
}
|
||||
|
||||
module.exports = new internals.String();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "joi",
|
||||
"description": "Object schema validation",
|
||||
"version": "6.0.6",
|
||||
"version": "6.0.8",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/hapijs/joi"
|
||||
|
@ -36,14 +36,14 @@
|
|||
"url": "http://github.com/hapijs/joi/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"gitHead": "6b73043cca1d030cbb1e51420c3848715edf2fe0",
|
||||
"gitHead": "bf45625841ff11e0a2795c332a98ed130511c9e3",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hapijs/joi/issues"
|
||||
},
|
||||
"homepage": "https://github.com/hapijs/joi",
|
||||
"_id": "joi@6.0.6",
|
||||
"_shasum": "fc448a19713f2a4ee39f92aee5872512be7f265a",
|
||||
"_from": "joi@latest",
|
||||
"_id": "joi@6.0.8",
|
||||
"_shasum": "c5e9e3d844f61a4a8d8a24382293d6df1d083be1",
|
||||
"_from": "joi@6.0.8",
|
||||
"_npmVersion": "1.4.28",
|
||||
"_npmUser": {
|
||||
"name": "marsup",
|
||||
|
@ -60,9 +60,9 @@
|
|||
}
|
||||
],
|
||||
"dist": {
|
||||
"shasum": "fc448a19713f2a4ee39f92aee5872512be7f265a",
|
||||
"tarball": "http://registry.npmjs.org/joi/-/joi-6.0.6.tgz"
|
||||
"shasum": "c5e9e3d844f61a4a8d8a24382293d6df1d083be1",
|
||||
"tarball": "http://registry.npmjs.org/joi/-/joi-6.0.8.tgz"
|
||||
},
|
||||
"directories": {},
|
||||
"_resolved": "https://registry.npmjs.org/joi/-/joi-6.0.6.tgz"
|
||||
"_resolved": "https://registry.npmjs.org/joi/-/joi-6.0.8.tgz"
|
||||
}
|
||||
|
|
|
@ -1118,7 +1118,7 @@ describe('any', function () {
|
|||
[{ b: 6 }, true],
|
||||
[{ a: 'b' }, true],
|
||||
[{ b: 5, a: 'x' }, true]
|
||||
], done)
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1277,4 +1277,3 @@ describe('any', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -724,7 +724,7 @@ describe('array', function () {
|
|||
var schema = Joi.array().items(Joi.array().items(Joi.number())).single();
|
||||
|
||||
Helper.validate(schema, [
|
||||
[[[1],[2],[3]], true],
|
||||
[[[1], [2], [3]], true],
|
||||
[[1, 2, 3], true],
|
||||
[[['a']], false, null, '"value" at position 0 fails because ["0" at position 0 fails because ["0" must be a number]]'],
|
||||
[['a'], false, null, '"value" at position 0 fails because ["0" must be an array]'],
|
||||
|
|
|
@ -129,4 +129,3 @@ describe('boolean', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ describe('date', function () {
|
|||
['1-1-2001 UTC', true],
|
||||
['1-1-2000 UTC', true],
|
||||
[0, false],
|
||||
["0", false],
|
||||
["-1", false],
|
||||
['0', false],
|
||||
['-1', false],
|
||||
['1-1-1999 UTC', false]
|
||||
], done);
|
||||
});
|
||||
|
@ -146,8 +146,8 @@ describe('date', function () {
|
|||
['1-1-1970 UTC', true],
|
||||
[0, true],
|
||||
[1, false],
|
||||
["0", true],
|
||||
["-1", true],
|
||||
['0', true],
|
||||
['-1', true],
|
||||
['1-1-2014 UTC', false]
|
||||
], done);
|
||||
});
|
||||
|
|
|
@ -285,5 +285,68 @@ describe('errors', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('annotates circular input', function (done) {
|
||||
|
||||
var schema = {
|
||||
x: Joi.object({
|
||||
y: Joi.object({
|
||||
z: Joi.number()
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
var input = {};
|
||||
input.x = input;
|
||||
|
||||
Joi.validate(input, schema, function (err, value) {
|
||||
|
||||
expect(err).to.exist();
|
||||
expect(err.annotate()).to.equal('{\n \"x\" \u001b[31m[1]\u001b[0m: \"[Circular ~]\"\n}\n\u001b[31m\n[1] \"x\" is not allowed\u001b[0m');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('annotates deep circular input', function (done) {
|
||||
|
||||
var schema = {
|
||||
x: Joi.object({
|
||||
y: Joi.object({
|
||||
z: Joi.number()
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
var input = { x: { y: {}}};
|
||||
input.x.y.z = input.x.y;
|
||||
|
||||
Joi.validate(input, schema, function (err, value) {
|
||||
|
||||
expect(err).to.exist();
|
||||
expect(err.annotate()).to.equal('{\n \"x\": {\n \"y\": {\n \"z\" \u001b[31m[1]\u001b[0m: \"[Circular ~.x.y]\"\n }\n }\n}\n\u001b[31m\n[1] \"z\" must be a number\u001b[0m');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('annotates deep circular input with extra keys', function (done) {
|
||||
|
||||
var schema = {
|
||||
x: Joi.object({
|
||||
y: Joi.object({
|
||||
z: Joi.number()
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
var input = { x: { y: { z: 1, foo: {}}}};
|
||||
input.x.y.foo = input.x.y;
|
||||
|
||||
Joi.validate(input, schema, function (err, value) {
|
||||
|
||||
expect(err).to.exist();
|
||||
expect(err.annotate()).to.equal('{\n \"x\": {\n \"y\" \u001b[31m[1]\u001b[0m: {\n \"z\": 1,\n \"foo\": \"[Circular ~.x.y]\"\n }\n }\n}\n\u001b[31m\n[1] \"foo\" is not allowed\u001b[0m');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,4 +31,3 @@ describe('func', function () {
|
|||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ var expect = Code.expect;
|
|||
exports.validate = function (schema, config, callback) {
|
||||
|
||||
return exports.validateOptions(schema, config, null, callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.validateOptions = function (schema, config, options, callback) {
|
||||
|
@ -67,4 +67,3 @@ exports.validateOptions = function (schema, config, options, callback) {
|
|||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1121,7 +1121,7 @@ describe('Joi', function () {
|
|||
|
||||
var localConfig = Joi.object({
|
||||
a: Joi.number().min(0).max(3),
|
||||
b: Joi.string().valid('a', 'b', 'c'),
|
||||
b: Joi.string().valid('a', 'b', 'c')
|
||||
}).options({ allowUnknown: true });
|
||||
|
||||
var obj = {
|
||||
|
@ -1404,7 +1404,7 @@ describe('Joi', function () {
|
|||
date: Joi.date(),
|
||||
child: Joi.object({
|
||||
alphanum: Joi.string().alphanum()
|
||||
}),
|
||||
})
|
||||
},
|
||||
min: [Joi.number(), Joi.string().min(3)],
|
||||
max: Joi.string().max(3),
|
||||
|
@ -1559,7 +1559,7 @@ describe('Joi', function () {
|
|||
var description = Joi.allow(null).describe();
|
||||
expect(description.invalids).to.not.exist();
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('#assert', function () {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"htmlparser2": "3.7.2",
|
||||
"http-errors": "1.2.8",
|
||||
"iced-coffee-script": "1.7.1-f",
|
||||
"joi": "6.0.6",
|
||||
"joi": "6.0.8",
|
||||
"jshint": "2.5.5",
|
||||
"marked": "0.3.2",
|
||||
"moment": "2.6.0",
|
||||
|
|
Loading…
Reference in New Issue