diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2020-06-08 21:30:20 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-06-19 18:36:21 +0300 |
commit | 2c4864762d2b97a55ef15fe44b7691d67de51766 (patch) | |
tree | 48fd0277a27dd788a60cc5efe501f89b4365f8a6 /lib/internal/util | |
parent | 52de4cb107a6fc1a06f7c98f4fd36c7f7fd539d5 (diff) |
util: gracefully handle unknown colors
This makes sure colors that are unknown won't cause an error. This
is especially important in case a library wants to use colors
defined by Node.js core, if available and fall back to the default
otherwise.
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: https://github.com/nodejs/node/pull/33797
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/util')
-rw-r--r-- | lib/internal/util/inspect.js | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 07e0f658e28..012f358e2ac 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -508,7 +508,8 @@ function stylizeWithColor(str, styleType) { const style = inspect.styles[styleType]; if (style !== undefined) { const color = inspect.colors[style]; - return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`; + if (color !== undefined) + return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`; } return str; } |