forked from mirrors/firefish
[mastodon-client] improve mention regexes
This commit is contained in:
parent
57fe933bb6
commit
006ff07a0c
|
@ -1280,8 +1280,8 @@ export default class Misskey implements MegalodonInterface {
|
|||
status.mentions = (await this.getMentions(status.plain_content!, cache)).filter(p => p != null);
|
||||
for (const m of status.mentions.filter((value, index, array) => array.indexOf(value) === index)) {
|
||||
if (m.acct == m.username)
|
||||
status.content = status.content.replace(`@${m.acct}@${this.baseUrlToHost(this.baseUrl)}`, `@${m.acct}`);
|
||||
status.content = status.content.replace(`@${m.acct}`, `<a href="${m.url}" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@${m.acct}</a>`);
|
||||
status.content = status.content.replace(new RegExp(`(?<=^|\\s|>)@${m.acct}@${this.baseUrlToHost(this.baseUrl)}(?=[^a-zA-Z0-9]|$)`, 'g'), `@${m.acct}`);
|
||||
status.content = status.content.replace(new RegExp(`(?<=^|\\s|>)@${m.acct}(?=[^a-zA-Z0-9]|$)`, 'g'), `<a href="${m.url}" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@${m.acct}</a>`);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
@ -1292,7 +1292,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
if (text == undefined)
|
||||
return mentions;
|
||||
|
||||
const mentionMatch = text.matchAll(/(?<=^|\s)@(?<user>.*?)(?:@(?<host>.*?)|)(?=\s|$)/g);
|
||||
const mentionMatch = text.matchAll(/(?<=^|\s)@(?<user>[a-zA-Z0-9_]+)(?:@(?<host>[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)(?=[^a-zA-Z0-9]|$)/g,);
|
||||
|
||||
for (const m of mentionMatch) {
|
||||
try {
|
||||
|
@ -2489,7 +2489,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
}
|
||||
|
||||
try {
|
||||
const match = q.match(/^@(?<user>.*?)(?:@(?<host>.*?)|)$/);
|
||||
const match = q.match(/^@(?<user>[a-zA-Z0-9_]+)(?:@(?<host>[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)$/);
|
||||
if (match) {
|
||||
const lookupQuery = {
|
||||
username: match.groups?.user,
|
||||
|
|
Loading…
Reference in a new issue