Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,14 @@ const meta = [
];

// Regex used for ansi escape code splitting
// Ref: https://github.com/chalk/ansi-regex/blob/f338e1814144efb950276aac84135ff86b72dc8e/index.js
// Ref: https://github.com/chalk/ansi-regex/blob/72bc570/index.js
// License: MIT by Sindre Sorhus <sindresorhus@gmail.com>
// Matches all ansi escape code sequences in a string
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',
'(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))' +
'|[\\u001B\\u009B][[\\]()#;?]*' +
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not complete consistent with
(?:;\d{0,4})*
(?:[;:]\d{0,4})*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?' +
'(?:(?:\\d{1,4}(?:[;:]\\d{0,4})*)?' +

'[\\dA-PR-TZcf-nq-uy=><~])', 'g',
);

let getStringWidth;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-util-stripvtcontrolcharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ for (const ST of ['\u0007', '\u001B\u005C', '\u009C']) {
tests.push(
[`\u001B]8;;mailto:no-replay@mail.com${ST}mail\u001B]8;;${ST}`, 'mail'],
[`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`, 'click'],
[`\u001B]8;;https://example.com/(foo${ST}label\u001B]8;;${ST}`, 'label'],
[`\u001B]8;;https://example.com/foo)bar${ST}label\u001B]8;;${ST}`, 'label'],
[`\u001B]8;;https://example.com/!foo${ST}label\u001B]8;;${ST}`, 'label'],
[`\u001B]8;;https://example.com/foo+bar${ST}label\u001B]8;;${ST}`, 'label'],
[`\u001B]8;;https://example.com/[foo]${ST}label\u001B]8;;${ST}`, 'label'],
);
}

Expand Down
Loading