extension object fails validation when used twice #2514
Open
Description
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 14.x
- module version with issue: 17.3.x
- last module version without issue: 16.x
- environment (e.g. node, browser, native): all
- used with (e.g. hapi application, another framework, standalone, ...): standalone
- any other relevant information: input validation issue
What are you trying to achieve or the steps to reproduce?
Trying to pass an extension object instance (rather than a generator function) to Joi twice results in a validation error due to a modification made by Joi.
import joi from 'https://cdn.skypack.dev/joi@~17.3.0';
const extension = {
type: 'foo',
base: joi.string(),
rules: {
bar: {
args: [{
name: 'baz',
assert: joi.string()
}],
validate(value, helpers, args, rule){
return { value }
}
}
}
}
// assume this is in the first library that uses Joi
const Joi = joi.extend(extension)
// assume this is another library or another direct usage. this call will produce an error
const Joi2 = joi.extend(extension)
What was the result you got?
Validation error.
What result did you expect?
For extension objects to be reusable without errors. Extend seems as if it should not have side effects on the extension objects passed.