From c5dd8712193d6415421c20ea89e4e89fb39f6563 Mon Sep 17 00:00:00 2001 From: Gary Steinert Date: Thu, 28 Dec 2017 06:44:09 +0000 Subject: [PATCH] Fix: TextType - Over-length value validates when both max and min specified #4536 --- fields/types/text/TextType.js | 2 +- fields/types/text/test/type.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fields/types/text/TextType.js b/fields/types/text/TextType.js index f21bd68581..8db99797f1 100644 --- a/fields/types/text/TextType.js +++ b/fields/types/text/TextType.js @@ -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); diff --git a/fields/types/text/test/type.js b/fields/types/text/test/type.js index bfe16d4ff1..9b182a2d2c 100644 --- a/fields/types/text/test/type.js +++ b/fields/types/text/test/type.js @@ -14,6 +14,11 @@ exports.initList = function (List) { type: String, min: 10, }, + minMaxChar: { + type: String, + min: 10, + max: 20, + }, }); }; @@ -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 () {