From fbc5e63731c59d9189ce1c031f59bcb570105e9d Mon Sep 17 00:00:00 2001 From: Elvis Adomnica Date: Fri, 12 Jan 2018 15:56:14 +0100 Subject: [PATCH] Disable hex4 and hex8 --- src/helpers/color.js | 4 +++- src/helpers/spec.js | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/helpers/color.js b/src/helpers/color.js index 5ca3e0a4..bc20465e 100644 --- a/src/helpers/color.js +++ b/src/helpers/color.js @@ -46,7 +46,9 @@ export default { }, isValidHex(hex) { - return tinycolor(hex).isValid() + // disable hex4 and hex8 + const lh = (String(hex).charAt(0) === '#') ? 1 : 0 + return hex.length !== (4 + lh) && hex.length < (7 + lh) && tinycolor(hex).isValid() }, getContrastingColor(data) { diff --git a/src/helpers/spec.js b/src/helpers/spec.js index 6681c67e..f6dd625d 100644 --- a/src/helpers/spec.js +++ b/src/helpers/spec.js @@ -92,15 +92,15 @@ describe('helpers/color', () => { }) describe('isValidHex', () => { - test('allows strings of length 3, 6, or 8', () => { + test('allows strings of length 3 or 6', () => { expect(color.isValidHex('f')).toBeFalsy() expect(color.isValidHex('ff')).toBeFalsy() expect(color.isValidHex('fff')).toBeTruthy() - // expect(color.isValidHex('ffff')).toBeFalsy() + expect(color.isValidHex('ffff')).toBeFalsy() expect(color.isValidHex('fffff')).toBeFalsy() expect(color.isValidHex('ffffff')).toBeTruthy() expect(color.isValidHex('fffffff')).toBeFalsy() - expect(color.isValidHex('ffffffff')).toBeTruthy() + expect(color.isValidHex('ffffffff')).toBeFalsy() expect(color.isValidHex('fffffffff')).toBeFalsy() expect(color.isValidHex('ffffffffff')).toBeFalsy() expect(color.isValidHex('fffffffffff')).toBeFalsy()