Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support joi 11 paths arrays. Fixes #3581. #3582

Merged
merged 1 commit into from Sep 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/validation.js
Expand Up @@ -86,7 +86,8 @@ internals.input = function (source, request, next) {
error.output.payload.validation = { source, keys: [] };
if (err.details) {
for (let i = 0; i < err.details.length; ++i) {
error.output.payload.validation.keys.push(Hoek.escapeHtml(err.details[i].path));
const path = err.details[i].path;
error.output.payload.validation.keys.push(Hoek.escapeHtml(Array.isArray(path) ? path.join('.') : path));
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/validation.js
Expand Up @@ -614,6 +614,41 @@ describe('validation', () => {
});
});

it('fails on invalid input (with joi 11 error)', (done) => {

// Fake the joi 11 format
const joiFakeError = new Error();
joiFakeError.details = [{ path: ['foo', 'bar'] }];

const server = new Hapi.Server();
server.connection();
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {

return reply('ok');
},
config: {
validate: {
query: {
a: Joi.number().error(joiFakeError)
}
}
}
});

server.inject('/?a=abc', (res) => {

expect(res.statusCode).to.equal(400);
expect(res.result.validation).to.equal({
source: 'query',
keys: ['foo.bar']
});
done();
});
});

it('ignores invalid input', (done) => {

const server = new Hapi.Server();
Expand Down