mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Fix URL matching in automod, censor, and spam plugin
This commit is contained in:
parent
682d8e9153
commit
9164bcd045
3 changed files with 23 additions and 1 deletions
|
@ -640,6 +640,7 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
|
|
||||||
protected evaluateMatchLinksTrigger(trigger: TMatchLinksTrigger, str: string): boolean {
|
protected evaluateMatchLinksTrigger(trigger: TMatchLinksTrigger, str: string): boolean {
|
||||||
const links = getUrlsInString(str, true);
|
const links = getUrlsInString(str, true);
|
||||||
|
|
||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
const normalizedHostname = link.hostname.toLowerCase();
|
const normalizedHostname = link.hostname.toLowerCase();
|
||||||
|
|
||||||
|
|
21
backend/src/utils.test.ts
Normal file
21
backend/src/utils.test.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import { getUrlsInString } from "./utils";
|
||||||
|
|
||||||
|
import test from "ava";
|
||||||
|
|
||||||
|
test("Detects full links", t => {
|
||||||
|
const urls = getUrlsInString("foo https://google.com/ bar");
|
||||||
|
t.is(urls.length, 1);
|
||||||
|
t.is(urls[0].hostname, "google.com");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Detects partial links", t => {
|
||||||
|
const urls = getUrlsInString("foo google.com bar");
|
||||||
|
t.is(urls.length, 1);
|
||||||
|
t.is(urls[0].hostname, "google.com");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Detects subdomains", t => {
|
||||||
|
const urls = getUrlsInString("foo photos.google.com bar");
|
||||||
|
t.is(urls.length, 1);
|
||||||
|
t.is(urls[0].hostname, "photos.google.com");
|
||||||
|
});
|
|
@ -189,7 +189,7 @@ const urlRegex = /(\S+\.\S+)/g;
|
||||||
const protocolRegex = /^[a-z]+:\/\//;
|
const protocolRegex = /^[a-z]+:\/\//;
|
||||||
|
|
||||||
export function getUrlsInString(str: string, unique = false): url.URL[] {
|
export function getUrlsInString(str: string, unique = false): url.URL[] {
|
||||||
let matches = (str.match(urlRegex) || []).map(m => m[0]);
|
let matches = str.match(urlRegex) || [];
|
||||||
if (unique) matches = Array.from(new Set(matches));
|
if (unique) matches = Array.from(new Set(matches));
|
||||||
|
|
||||||
return matches.reduce((urls, match) => {
|
return matches.reduce((urls, match) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue