[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);
|
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)) {
|
for (const m of status.mentions.filter((value, index, array) => array.indexOf(value) === index)) {
|
||||||
if (m.acct == m.username)
|
if (m.acct == m.username)
|
||||||
status.content = status.content.replace(`@${m.acct}@${this.baseUrlToHost(this.baseUrl)}`, `@${m.acct}`);
|
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(`@${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}(?=[^a-zA-Z0-9]|$)`, 'g'), `<a href="${m.url}" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@${m.acct}</a>`);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1292,7 +1292,7 @@ export default class Misskey implements MegalodonInterface {
|
||||||
if (text == undefined)
|
if (text == undefined)
|
||||||
return mentions;
|
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) {
|
for (const m of mentionMatch) {
|
||||||
try {
|
try {
|
||||||
|
@ -2489,7 +2489,7 @@ export default class Misskey implements MegalodonInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
if (match) {
|
||||||
const lookupQuery = {
|
const lookupQuery = {
|
||||||
username: match.groups?.user,
|
username: match.groups?.user,
|
||||||
|
|
Loading…
Reference in a new issue