Skip to content

Commit

Permalink
check: persist values sanitized via oneOf()
Browse files Browse the repository at this point in the history
Fixes #565
  • Loading branch information
gustavohenke committed Apr 29, 2018
1 parent fe1f179 commit af53398
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions check/one-of.js
@@ -1,4 +1,5 @@
const _ = require('lodash');
const persistValues = require('../utils/persist-values');
const runner = require('./runner');

module.exports = (validationChains, message) => (req, res, next) => {
Expand Down Expand Up @@ -29,6 +30,7 @@ module.exports = (validationChains, message) => (req, res, next) => {
});
}

contexts.forEach(context => persistValues(req, context));
next();
return results;
}).catch(next);
Expand Down
13 changes: 13 additions & 0 deletions check/one-of.spec.js
Expand Up @@ -54,6 +54,19 @@ describe('check: checkOneOf middleware', () => {
});
});

it('persists sanitized values', () => {
const req = {
cookies: { foo: ' bar ' }
};

return oneOf([
check('foo').trim(),
[check('foo').customSanitizer(value => value.toUpperCase())]
])(req, {}, () => {}).then(() => {
expect(req.cookies.foo).to.equal('BAR');
});
});

describe('error message', () => {
it('is "Invalid value(s)" by default', done => {
const req = {
Expand Down

0 comments on commit af53398

Please sign in to comment.