diff options
| author | Zach <zachauten@gmail.com> | 2022-02-06 05:00:06 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-06 19:00:06 +0900 |
| commit | a7850d7fe6c52225acd614167495d765ed2385f3 (patch) | |
| tree | b0be510c0d6e0f23570a4710b30184ba4aee107b /ext | |
| parent | 8cc9a9350b8a8c8fb883a93fc78471ccdd545481 (diff) | |
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
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/console/02_console.js | 32 |
1 files changed, 24 insertions, 8 deletions
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) { |
