diff --git a/src/utils/validate.js b/src/utils/validate.js index 6b3ac418..3e91b294 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -33,6 +33,8 @@ export function validURL(url) { * @returns {Boolean} */ export function validLowerCase(str) { + // https://www.coder.work/article/1041931 + if (str === undefined || str === null) return false const reg = /^[a-z]+$/ return reg.test(str) } @@ -42,6 +44,8 @@ export function validLowerCase(str) { * @returns {Boolean} */ export function validUpperCase(str) { + // https://www.coder.work/article/1041931 + if (str === undefined || str === null) return false const reg = /^[A-Z]+$/ return reg.test(str) } diff --git a/tests/unit/utils/validate.spec.js b/tests/unit/utils/validate.spec.js index ef2efe61..595d5441 100644 --- a/tests/unit/utils/validate.spec.js +++ b/tests/unit/utils/validate.spec.js @@ -14,11 +14,13 @@ describe('Utils:validate', () => { expect(validLowerCase('abc')).toBe(true) expect(validLowerCase('Abc')).toBe(false) expect(validLowerCase('123abc')).toBe(false) + expect(validLowerCase()).toBe(false) }) it('validUpperCase', () => { expect(validUpperCase('ABC')).toBe(true) expect(validUpperCase('Abc')).toBe(false) expect(validUpperCase('123ABC')).toBe(false) + expect(validUpperCase()).toBe(false) }) it('validAlphabets', () => { expect(validAlphabets('ABC')).toBe(true)