From 0bafe087e45d89439966273b00d073710468d5a6 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 11 Dec 2019 11:12:26 +0100 Subject: [PATCH] readline: update ansi-regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This updates the used regular expression to the latest version. It includes a number of additional escape codes. PR-URL: https://github.com/nodejs/node/pull/30907 Reviewed-By: Michaƫl Zasso Reviewed-By: Rich Trott --- lib/internal/readline/utils.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/internal/readline/utils.js b/lib/internal/readline/utils.js index 510acf221831a0..ae7eb54af29adf 100644 --- a/lib/internal/readline/utils.js +++ b/lib/internal/readline/utils.js @@ -3,16 +3,18 @@ const { Boolean, NumberIsInteger, + RegExp, } = primordials; // Regex used for ansi escape code splitting // Adopted from https://github.com/chalk/ansi-regex/blob/master/index.js -// License: MIT, authors: @sindresorhus, Qix-, and arjunmehta +// License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore // Matches all ansi escape code sequences in a string -/* eslint-disable no-control-regex */ -const ansi = - /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; -/* eslint-enable no-control-regex */ +const ansiPattern = '[\\u001B\\u009B][[\\]()#;?]*' + + '(?:(?:(?:[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 kUTF16SurrogateThreshold = 0x10000; // 2 ** 16 const kEscape = '\x1b';