diff options
author | Simon Ser <contact@emersion.fr> | 2024-03-02 12:36:30 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2024-03-02 12:36:30 +0100 |
commit | 5d3738bc40f9e4cb275146f762b3ec9de9492ce0 (patch) | |
tree | c01a9a5e0c2fcb725208ad72313678e5934ff91b | |
parent | 429b4595e7a8f37920f933944297c1a6fd0e5a38 (diff) | |
download | gamja-5d3738bc40f9e4cb275146f762b3ec9de9492ce0.tar.gz gamja-5d3738bc40f9e4cb275146f762b3ec9de9492ce0.zip |
lib/irc: ignore highlights in URLs
-rw-r--r-- | lib/irc.js | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -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; } |