Skip to content

Commit 83d2862

Browse files
committed
Restore original regex global flag use
Including the flag in the original, shared regex requires resetting `lastIndex` after each use. You'll get unexpected results otherwise. Also fixes all failing tests for `getLinks()`.
1 parent d8e8f2f commit 83d2862

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Diff for: lib/chat-utils/link-regex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1427,5 +1427,5 @@ const scheme = '(https?|ftp|wss?)://';
14271427
const strict = `\\b${scheme}${pathCont}`;
14281428
const relaxed = `${strict}|${webURL}`;
14291429

1430-
const linkRegex = new RegExp(relaxed, 'gi');
1430+
const linkRegex = new RegExp(relaxed, 'i');
14311431
module.exports = linkRegex;

Diff for: lib/services/message-matching.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
},
77
getLinks(message) {
88
return Array.from(
9-
message.matchAll(linkRegex),
9+
message.matchAll(new RegExp(linkRegex, 'g')),
1010
(k) => (k[0].startsWith('http') ? k[0] : `http://${k[0]}`), // add protocol to link
1111
)
1212
.map((link) => {

0 commit comments

Comments
 (0)