diff --git a/lib/revalidator.js b/lib/revalidator.js index 0c0160f..5ee3e42 100644 --- a/lib/revalidator.js +++ b/lib/revalidator.js @@ -321,7 +321,7 @@ switch (type || (isArray(value) ? 'array' : typeof value)) { case 'string': - constrain('allowEmpty', value, function (a, e) { return e ? e : a !== '' }); + constrain('allowEmpty', value, function (a, e) { return e ? e : a.trim() !== '' }); constrain('minLength', value.length, function (a, e) { return a >= e }); constrain('maxLength', value.length, function (a, e) { return a <= e }); constrain('pattern', value, function (a, e) { diff --git a/test/validator-test.js b/test/validator-test.js index 195b690..55eaa44 100644 --- a/test/validator-test.js +++ b/test/validator-test.js @@ -112,6 +112,7 @@ vows.describe('revalidator', { "with ": assertValidates ("boom", "kaboom", { maxLength: 4 }), "with ": assertValidates ("kaboom", "boom", { minLength: 6 }), "with ": assertValidates ("hello", "", { allowEmpty: false }), + "with ": assertValidates ("a b", " ", { allowEmpty: false }), "with ": assertValidates ( 512, 43, { minimum: 473 }), "with ": assertValidates ( 512, 1949, { maximum: 678 }), "with ": assertValidates ( 10, 9, { divisibleBy: 5 }),