From a3c2ef9e98ffc9839c82d18e1a9a2d13efbd0456 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Mon, 9 Sep 2024 11:49:18 -0400 Subject: [PATCH] util: update ansi regex PR-URL: https://github.com/nodejs/node/pull/54865 Refs: https://github.com/chalk/ansi-regex/pull/58 Reviewed-By: Ruben Bridgewater Reviewed-By: Marco Ippolito Reviewed-By: Moshe Atlow Reviewed-By: James M Snell --- lib/internal/util/inspect.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 01c1548ea398b5..b46038425b8c70 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -241,14 +241,17 @@ const meta = [ ]; // Regex used for ansi escape code splitting -// Adopted from https://github.com/chalk/ansi-regex/blob/HEAD/index.js -// License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore +// Ref: https://github.com/chalk/ansi-regex/blob/f338e1814144efb950276aac84135ff86b72dc8e/index.js +// License: MIT by Sindre Sorhus // Matches all ansi escape code sequences in a string -const ansiPattern = '[\\u001B\\u009B][[\\]()#;?]*' + - '(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*' + - '|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)' + - '|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'; -const ansi = new RegExp(ansiPattern, 'g'); +const ansi = new RegExp( + '[\\u001B\\u009B][[\\]()#;?]*' + + '(?:(?:(?:(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]+)*' + + '|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/\\#&.:=?%@~_]*)*)?' + + '(?:\\u0007|\\u001B\\u005C|\\u009C))' + + '|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?' + + '[\\dA-PR-TZcf-nq-uy=><~]))', 'g', +); let getStringWidth;