From e9ed4751d4264561ce5c1d1d5bc8394b42329abd Mon Sep 17 00:00:00 2001 From: LitoMore Date: Fri, 22 Feb 2019 13:44:26 +0800 Subject: [PATCH 1/2] Fix patterns --- index.js | 2 +- test.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 76d354a..c254480 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ module.exports = options => { }, options); const pattern = [ - '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', + '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' ].join('|'); diff --git a/test.js b/test.js index acc59de..f8b4519 100644 --- a/test.js +++ b/test.js @@ -41,7 +41,20 @@ test('match only first', t => { t.is('foo\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})).length, 1); }); -test.failing('match "change icon name and window title" in string', t => { +test('match terminal link', t => { + t.regex('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007', ansiRegex()); + t.regex('\u001B]8;;mailto:no-replay@mail.com\u0007mail\u001B]8;;\u0007', ansiRegex()); + t.deepEqual('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()), [ + '\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007', + '\u001B]8;;\u0007' + ]); + t.deepEqual('\u001B]8;;mailto:no-reply@mail.com\u0007mail-me\u001B]8;;\u0007'.match(ansiRegex()), [ + '\u001B]8;;mailto:no-reply@mail.com\u0007', + '\u001B]8;;\u0007' + ]); +}); + +test('match "change icon name and window title" in string', t => { t.is('\u001B]0;sg@tota:~/git/\u0007\u001B[01;32m[sg@tota\u001B[01;37m misc-tests\u001B[01;32m]$'.match(ansiRegex())[0], '\u001B]0;sg@tota:~/git/\u0007'); }); From c287fb2cb01520cbec43fbe0ce9696bd6b94c087 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sun, 24 Feb 2019 12:35:58 +0800 Subject: [PATCH 2/2] Add document for terminal link --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 7212145..d19c446 100644 --- a/readme.md +++ b/readme.md @@ -40,6 +40,9 @@ ansiRegex().test('cake'); '\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})); //=> ['\u001B[4m'] + +'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex()); +//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007'] ```