diff --git a/sanitizer/_text.js b/sanitizer/_text.js index cb4dc737..bae2d4a1 100644 --- a/sanitizer/_text.js +++ b/sanitizer/_text.js @@ -13,11 +13,12 @@ function _sanitize( raw, clean ){ // invalid input 'text' // must call `!check.nonEmptyString` since `check.emptyString` returns // `false` for `undefined` and `null` - if( !check.nonEmptyString( raw.text ) ){ - messages.errors.push('invalid param \'text\': text length, must be >0'); + const text = _.trim( _.trim( raw.text ), QUOTES ); + if( !check.nonEmptyString( text ) ){ + messages.errors.push('invalid param \'text\': text length, must be >0'); } else { - clean.text = _.trim( _.trim( raw.text ), QUOTES ); + clean.text = text; } return messages; diff --git a/test/unit/sanitizer/_text.js b/test/unit/sanitizer/_text.js index 7a35fbbe..6a368b41 100644 --- a/test/unit/sanitizer/_text.js +++ b/test/unit/sanitizer/_text.js @@ -124,6 +124,20 @@ module.exports.tests.text_parser = function(test, common) { t.deepEquals(validParameters, expected); t.end(); }); + + test('whitespace-only input counts as empty', (t) => { + const raw = { text: ' ' }; + const clean = {}; + + const expected_clean = {}; + + const messages = sanitizer.sanitize(raw, clean); + + t.deepEquals(clean, expected_clean); + t.deepEquals(messages.errors, ['invalid param \'text\': text length, must be >0']); + t.deepEquals(messages.warnings, [], 'no warnings'); + t.end(); + }); }; module.exports.all = (tape, common) => {