diff --git a/src/core/utils.js b/src/core/utils.js index 1e2a95b1..5e8ac79e 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -549,7 +549,7 @@ export const validateParam = (param, isXml) => { let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer - if (maxLength) { + if (maxLength || maxLength === 0) { let err = validateMaxLength(value, maxLength) if (err) errors.push(err) } diff --git a/test/core/utils.js b/test/core/utils.js index 2e21ae3c..40d7fc41 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -207,6 +207,7 @@ describe("utils", function() { }) it("returns a message for invalid input'", function() { + expect(validateMaxLength("abc", 0)).toEqual(errorMessage) expect(validateMaxLength("abc", 1)).toEqual(errorMessage) expect(validateMaxLength("abc", 2)).toEqual(errorMessage) }) @@ -272,7 +273,7 @@ describe("utils", function() { expect( result ).toEqual( [] ) }) - it("validates required strings with min and max length", function() { + it("validates required strings with min and max length", function() { // invalid string with max length param = fromJS({ required: true, @@ -283,6 +284,17 @@ describe("utils", function() { result = validateParam( param, false ) expect( result ).toEqual( ["Value must be less than MaxLength"] ) + // invalid string with max length 0 + param = fromJS({ + required: true, + type: "string", + value: "test string", + maxLength: 0 + }) + result = validateParam( param, false ) + expect( result ).toEqual( ["Value must be less than MaxLength"] ) + + // invalid string with min length param = fromJS({ required: true,