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

Fix: TextType - Over-length value validates when both max and min spe… #4537

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion fields/types/text/TextType.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ text.prototype.validateInput = function (data, callback) {
if (max && typeof value === 'string') {
result = value.length < max;
}
if (min && typeof value === 'string') {
if (result && min && typeof value === 'string') {
result = value.length > min;
}
utils.defer(callback, result);
Expand Down
19 changes: 19 additions & 0 deletions fields/types/text/test/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ exports.initList = function (List) {
type: String,
min: 10,
},
minMaxChar: {
type: String,
min: 10,
max: 20,
},
});
};

Expand Down Expand Up @@ -151,6 +156,20 @@ exports.testFieldType = function (List) {
});
});

it('should invalidate string shorter than min characters when both min and max are specified', function (done) {
List.fields.minMaxChar.validateInput({ minMaxChar: 'Short' }, function (result) {
demand(result).be.false();
done();
});
});

it('should invalidate string longer than max characters when both min and max are specified', function (done) {
List.fields.minMaxChar.validateInput({ minMaxChar: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, function (result) {
demand(result).be.false();
done();
});
});

});

describe('validateRequiredInput', function () {
Expand Down