Skip to content

Commit

Permalink
fix(isLength): return true if min no supplied (#1070)
Browse files Browse the repository at this point in the history
- ensure that even when user does not pass max and min, set defaults for the same
- instance, validator.isLength('aa') returns false, instead, we should return true and set min as 0 and max as undefined
- close #939
  • Loading branch information
ezkemboi authored and profnandaa committed Aug 2, 2019
1 parent 25e84cf commit 1ce76a1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/isLength.js
Expand Up @@ -22,7 +22,7 @@ function isLength(str, options) {
max = options.max;
} else {
// backwards compatibility: isLength(str, min [, max])
min = arguments[1];
min = arguments[1] || 0;
max = arguments[2];
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/isLength.js
Expand Up @@ -9,7 +9,7 @@ export default function isLength(str, options) {
min = options.min || 0;
max = options.max;
} else { // backwards compatibility: isLength(str, min [, max])
min = arguments[1];
min = arguments[1] || 0;
max = arguments[2];
}
const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
Expand Down
4 changes: 4 additions & 0 deletions test/validators.js
Expand Up @@ -2795,6 +2795,10 @@ describe('Validators', () => {
valid: [''],
invalid: ['a', 'ab'],
});
test({
validator: 'isLength',
valid: ['a', '', 'asds'],
});
});

it('should validate strings by byte length', () => {
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Expand Up @@ -1007,7 +1007,7 @@ function isLength(str, options) {
max = options.max;
} else {
// backwards compatibility: isLength(str, min [, max])
min = arguments[1];
min = arguments[1] || 0;
max = arguments[2];
}

Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 1ce76a1

Please sign in to comment.