Skip to content

Commit

Permalink
Fix annotate() exception. Closes #1203
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed May 28, 2017
1 parent 5886567 commit 539760b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2012-2016, Project contributors
Copyright (c) 2012-2017, Project contributors
Copyright (c) 2012-2014, Walmart
All rights reserved.

Expand Down
8 changes: 5 additions & 3 deletions lib/errors.js 100644 → 100755
Expand Up @@ -301,11 +301,13 @@ internals.annotate = function (stripColorCodes) {
const seg = path[j];

if (ref.isImmutable) {
// Joi schemas are not cloned by hoek, we have to take this extra step
ref = ref.clone();
ref = ref.clone(); // joi schemas are not cloned by hoek, we have to take this extra step
}

if (j + 1 < path.length && typeof ref[seg] !== 'string') {
if (j + 1 < path.length &&
ref[seg] &&
typeof ref[seg] !== 'string') {

ref = ref[seg];
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "joi",
"description": "Object schema validation",
"version": "10.5.0",
"version": "10.5.1",
"homepage": "https://github.com/hapijs/joi",
"repository": "git://github.com/hapijs/joi",
"main": "lib/index.js",
Expand Down
30 changes: 30 additions & 0 deletions test/errors.js 100644 → 100755
Expand Up @@ -590,5 +590,35 @@ describe('errors', () => {
done();
});
});

it('handles child to uncle relationship inside a child', (done) => {

const object = {
response: {
options: {
stripUnknown: true
}
}
};

const schema = Joi.object({
response: Joi.object({
modify: Joi.boolean(),
options: Joi.object()
})
.assert('options.stripUnknown', Joi.ref('modify'), 'meet requirement of having peer modify set to true')
});

Joi.validate(object, schema, { abortEarly: false }, (err, value) => {

expect(err).to.exist();
expect(() => {

err.annotate(true);
}).to.not.throw();

done();
});
});
});
});

0 comments on commit 539760b

Please sign in to comment.