lib/irc: ignore highlights in URLs

This commit is contained in:
Simon Ser 2024-03-02 12:36:30 +01:00
parent 429b4595e7
commit 5d3738bc40

View File

@ -264,6 +264,7 @@ const alphaNum = (() => {
return new RegExp(/^[a-zA-Z0-9]$/, "u");
}
})();
const space = new RegExp(/\s/);
function isWordBoundary(ch) {
switch (ch) {
@ -276,6 +277,29 @@ function isWordBoundary(ch) {
}
}
function isURIPrefix(text) {
let i = text.search(space);
if (i >= 0) {
text = text.slice(i);
}
i = text.indexOf("://");
if (i <= 0) {
return false;
}
// See RFC 3986 section 3
let ch = text[i - 1];
switch (ch) {
case "+":
case "-":
case ".":
return true;
default:
return alphaNum.test(ch);
}
}
export function isHighlight(msg, nick, cm) {
if (msg.command != "PRIVMSG" && msg.command != "NOTICE") {
return false;
@ -302,7 +326,7 @@ export function isHighlight(msg, nick, cm) {
if (i + nick.length < text.length) {
right = text[i + nick.length];
}
if (isWordBoundary(left) && isWordBoundary(right)) {
if (isWordBoundary(left) && isWordBoundary(right) && !isURIPrefix(text.slice(0, i))) {
return true;
}