Skip to content

Commit 2ae99de

Browse files
committed
fix: handle all valid ST characters
According to wiki, all of [0x1b5c, 0x07, 0x9C] are valid ST (string terminator) signals, so support them all.
1 parent 02fa893 commit 2ae99de

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default function ansiRegex({onlyFirst = false} = {}) {
22
const pattern = [
3-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
3+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))',
44
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
55
].join('|');
66

test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ test('match only first', t => {
4343
});
4444

4545
test('match terminal link', t => {
46-
t.regex('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007', ansiRegex());
47-
t.regex('\u001B]8;;mailto:[email protected]\u0007mail\u001B]8;;\u0007', ansiRegex());
48-
t.deepEqual('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()), [
49-
'\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007',
50-
'\u001B]8;;\u0007'
51-
]);
52-
t.deepEqual('\u001B]8;;mailto:[email protected]\u0007mail-me\u001B]8;;\u0007'.match(ansiRegex()), [
53-
'\u001B]8;;mailto:[email protected]\u0007',
54-
'\u001B]8;;\u0007'
55-
]);
46+
for (const ST of ['\u0007', '\u001B\u005C', '\u009C']) {
47+
t.regex(`\u000B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`, ansiRegex());
48+
t.regex(`\u001B]8;;mailto:[email protected]${ST}mail\u001B]8;;${ST}`, ansiRegex());
49+
t.deepEqual(`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`.match(ansiRegex()), [
50+
`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}`,
51+
`\u001B]8;;${ST}`
52+
]);
53+
t.deepEqual(`\u001B]8;;mailto:[email protected]${ST}mail-me\u001B]8;;${ST}`.match(ansiRegex()), [
54+
`\u001B]8;;mailto:[email protected]${ST}`,
55+
`\u001B]8;;${ST}`
56+
]);
57+
}
5658
});
5759

5860
test('match "change icon name and window title" in string', t => {

0 commit comments

Comments
 (0)