From e60fd28bb979ee6d12fb83bc131f9f70b61318bf Mon Sep 17 00:00:00 2001 From: Rajasegar Chandran Date: Sun, 6 Jun 2021 12:33:24 +0530 Subject: [PATCH] fix: guard border utils against uncommon values --- src/border-utils.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/border-utils.js b/src/border-utils.js index d72cd78..31303ab 100644 --- a/src/border-utils.js +++ b/src/border-utils.js @@ -25,24 +25,27 @@ function getBorderUtils(decl) { if (decl.value === 'none') return ''; if (decl.value === 'transparent') return ''; if (decl.value === '0') return 'border-0'; - const [width, style, color] = decl.value.split(' '); - - const borderWidth = TAILWIND_CLASSES['border-width']; - const borderStyle = TAILWIND_CLASSES['border-style']; - const borderColor = TAILWIND_CLASSES['border-color']; - const borderOpacity = TAILWIND_CLASSES['border-opacity']; - - const _width = borderWidth[width] || 'border'; - const _style = borderStyle[style] || ''; - const _color = borderColor[color] || getColorUtils(decl); - let result = _width + ' ' + _style + ' ' + _color; - if (color.includes('rgba')) { - const [, , , opacity] = chroma(color)._rgb; - const proximateKey = getProximateKey(borderOpacity, opacity); - const _opacity = borderOpacity[opacity] || borderOpacity[proximateKey]; - result += ' ' + _opacity; - } - return result; + const borderValues = decl.value.split(' '); + if (borderValues.length === 3) { + const [width, style, color] = borderValues; + + const borderWidth = TAILWIND_CLASSES['border-width']; + const borderStyle = TAILWIND_CLASSES['border-style']; + const borderColor = TAILWIND_CLASSES['border-color']; + const borderOpacity = TAILWIND_CLASSES['border-opacity']; + + const _width = borderWidth[width] || 'border'; + const _style = borderStyle[style] || ''; + const _color = borderColor[color] || getColorUtils(decl); + let result = _width + ' ' + _style + ' ' + _color; + if (color.includes('rgba')) { + const [, , , opacity] = chroma(color)._rgb; + const proximateKey = getProximateKey(borderOpacity, opacity); + const _opacity = borderOpacity[opacity] || borderOpacity[proximateKey]; + result += ' ' + _opacity; + } + return result; + } else return ''; } module.exports = getBorderUtils;