From 0ff1f7ca65c85ac29f4229e3601e2148c9d7ff99 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 18 Jul 2023 15:57:54 +0200 Subject: [PATCH] [mastodon-client] improve mention regexes --- packages/megalodon/src/misskey.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index faae6e56a..491375ad8 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1522,11 +1522,11 @@ export default class Misskey implements MegalodonInterface { )) { if (m.acct == m.username) status.content = status.content.replace( - `@${m.acct}@${this.baseUrlToHost(this.baseUrl)}`, + new RegExp(`(?<=^|\\s|>)@${m.acct}@${this.baseUrlToHost(this.baseUrl)}(?=[^a-zA-Z0-9]|$)`, 'g'), `@${m.acct}`, ); status.content = status.content.replace( - `@${m.acct}`, + new RegExp(`(?<=^|\\s|>)@${m.acct}(?=[^a-zA-Z0-9]|$)`, 'g'), `@${m.acct}`, ); } @@ -1542,7 +1542,7 @@ export default class Misskey implements MegalodonInterface { if (text == undefined) return mentions; const mentionMatch = text.matchAll( - /(?<=^|\s)@(?.*?)(?:@(?.*?)|)(?=\s|$)/g, + /(?<=^|\s)@(?[a-zA-Z0-9_]+)(?:@(?[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)(?=[^a-zA-Z0-9]|$)/g, ); for (const m of mentionMatch) { @@ -2963,7 +2963,7 @@ export default class Misskey implements MegalodonInterface { } try { - const match = q.match(/^@(?.*?)(?:@(?.*?)|)$/); + const match = q.match(/^@(?[a-zA-Z0-9_]+)(?:@(?[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)$/); if (match) { const lookupQuery = { username: match.groups?.user,