From a7850d7fe6c52225acd614167495d765ed2385f3 Mon Sep 17 00:00:00 2001 From: Zach Date: Sun, 6 Feb 2022 05:00:06 -0500 Subject: fix(ext/console): fix uncaught TypeError in css styling (#13567) When using css coloring in the console, non-color values should be ignored rather than throw exceptions. Fixes #13469 --- ext/console/02_console.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'ext/console') diff --git a/ext/console/02_console.js b/ext/console/02_console.js index d3734b6a4..3020c0794 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -1621,10 +1621,18 @@ } else if (css.backgroundColor == "white") { ansi += `\x1b[47m`; } else { - const [r, g, b] = ArrayIsArray(css.backgroundColor) - ? css.backgroundColor - : parseCssColor(css.backgroundColor); - ansi += `\x1b[48;2;${r};${g};${b}m`; + if (ArrayIsArray(css.backgroundColor)) { + const [r, g, b] = css.backgroundColor; + ansi += `\x1b[48;2;${r};${g};${b}m`; + } else { + const parsed = parseCssColor(css.backgroundColor); + if (parsed !== null) { + const [r, g, b] = parsed; + ansi += `\x1b[48;2;${r};${g};${b}m`; + } else { + ansi += "\x1b[49m"; + } + } } } if (!colorEquals(css.color, prevCss.color)) { @@ -1647,10 +1655,18 @@ } else if (css.color == "white") { ansi += `\x1b[37m`; } else { - const [r, g, b] = ArrayIsArray(css.color) - ? css.color - : parseCssColor(css.color); - ansi += `\x1b[38;2;${r};${g};${b}m`; + if (ArrayIsArray(css.color)) { + const [r, g, b] = css.color; + ansi += `\x1b[38;2;${r};${g};${b}m`; + } else { + const parsed = parseCssColor(css.color); + if (parsed !== null) { + const [r, g, b] = parsed; + ansi += `\x1b[38;2;${r};${g};${b}m`; + } else { + ansi += "\x1b[39m"; + } + } } } if (css.fontWeight != prevCss.fontWeight) { -- cgit v1.2.3