Skip to content

Commit e96b184

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 e96b184

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ 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+
const STs = ['\u0007', '\u001B\u005C', '\u009C']
47+
STs.forEach(ST => {
48+
t.regex(`\u000B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`, ansiRegex());
49+
t.regex(`\u001B]8;;mailto:[email protected]${ST}mail\u001B]8;;${ST}`, ansiRegex());
50+
t.deepEqual(`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}click\u001B]8;;${ST}`.match(ansiRegex()), [
51+
`\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le${ST}`,
52+
`\u001B]8;;${ST}`
53+
]);
54+
t.deepEqual(`\u001B]8;;mailto:[email protected]${ST}mail-me\u001B]8;;${ST}`.match(ansiRegex()), [
55+
`\u001B]8;;mailto:[email protected]${ST}`,
56+
`\u001B]8;;${ST}`
57+
]);
58+
})
5659
});
5760

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

0 commit comments

Comments
 (0)