forked from CringeStudios/gamja
lib/irc: ignore highlights in URLs
This commit is contained in:
parent
429b4595e7
commit
5d3738bc40
26
lib/irc.js
26
lib/irc.js
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user