aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2024-03-02 12:36:30 +0100
committerSimon Ser <contact@emersion.fr>2024-03-02 12:36:30 +0100
commit5d3738bc40f9e4cb275146f762b3ec9de9492ce0 (patch)
treec01a9a5e0c2fcb725208ad72313678e5934ff91b
parent429b4595e7a8f37920f933944297c1a6fd0e5a38 (diff)
downloadgamja-5d3738bc40f9e4cb275146f762b3ec9de9492ce0.tar.gz
gamja-5d3738bc40f9e4cb275146f762b3ec9de9492ce0.zip
lib/irc: ignore highlights in URLs
-rw-r--r--lib/irc.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/irc.js b/lib/irc.js
index 86fa65a..991c47d 100644
--- a/lib/irc.js
+++ b/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;
}