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; }