+21
-1
@@ -55,6 +55,13 @@ 'use strict'; | ||
| validate(value, { schema, state, prefs }) { | ||
| validate(value, { schema, state, prefs, error }) { | ||
| assert(schema.$_terms.link, 'Uninitialized link schema'); | ||
| const limit = schema._flags.maxRecursion; | ||
| if (limit !== undefined && | ||
| state.schemas.filter((entry) => entry.schema === schema).length > limit) { | ||
| return { value, errors: error('link.maxRecursion', { limit }) }; | ||
| } | ||
| const linked = internals.generate(schema, value, state, prefs); | ||
@@ -93,5 +100,18 @@ const ref = schema.$_terms.link[0].ref; | ||
| } | ||
| }, | ||
| maxRecursion: { | ||
| method(limit) { | ||
| assert(Number.isSafeInteger(limit) && limit >= 1, 'limit must be a positive integer'); | ||
| return this.$_setFlag('maxRecursion', limit); | ||
| } | ||
| } | ||
| }, | ||
| messages: { | ||
| 'link.maxRecursion': '{{#label}} exceeds maximum recursion depth of {{#limit}}' | ||
| }, | ||
| overrides: { | ||
@@ -98,0 +118,0 @@ |
+1
-1
| { | ||
| "name": "joi", | ||
| "description": "Object schema validation", | ||
| "version": "18.1.2", | ||
| "version": "18.2.0", | ||
| "repository": { | ||
@@ -6,0 +6,0 @@ "url": "git://github.com/hapijs/joi.git", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
10890
0.17%583510
-0.18%