Skip to content

Commit d8e8f2f

Browse files
committed
new URL crash protection.
1 parent 0778b94 commit d8e8f2f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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, 'i');
1430+
const linkRegex = new RegExp(relaxed, 'gi');
14311431
module.exports = linkRegex;

lib/services/message-matching.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ module.exports = {
55
return linkRegex.test(message);
66
},
77
getLinks(message) {
8-
return Array.from(message.matchAll(new RegExp(linkRegex, 'g')), (k) => new URL(k[0]));
8+
return Array.from(
9+
message.matchAll(linkRegex),
10+
(k) => (k[0].startsWith('http') ? k[0] : `http://${k[0]}`), // add protocol to link
11+
)
12+
.map((link) => {
13+
try {
14+
return new URL(link); // crash protection
15+
} catch (e) {
16+
return null;
17+
}
18+
})
19+
.filter((link) => link); // remove null
920
},
1021
mentionsUser(message, user) {
1122
if (!user) return false;

0 commit comments

Comments
 (0)