From b94aeb2df23ad11847cc75d543a40466e7449443 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 5 Jan 2024 14:01:31 +0100 Subject: [PATCH] server: try to fix link parsing from wafrn.net Changelog: Fixed --- packages/backend/src/mfm/from-html.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/mfm/from-html.ts b/packages/backend/src/mfm/from-html.ts index e745777bf..b00c86741 100644 --- a/packages/backend/src/mfm/from-html.ts +++ b/packages/backend/src/mfm/from-html.ts @@ -68,14 +68,16 @@ export function fromHtml(html: string, quoteUri?: string | null): string { case 'a': { - const txt = getText(node); + // trim spaces away, because some AP servers (app.wafrn.net) send strange + // zero width non-break space in strange places and things like that + const txt = getText(node).trim(); const href = getAttr(node, 'href'); // hashtags if (txt.startsWith('#') && href && (attrHas(node, 'rel', 'tag') || attrHas(node, 'class', 'hashtag'))) { text += txt; - // mentions - } else if (txt.startsWith('@') && !attrHas(node, 'rel', 'me')) { + // mentions: a link that starts with `@` and does not include space + } else if (txt.startsWith('@') && txt.match(/\s/) == null && !attrHas(node, 'rel', 'me')) { const part = txt.split('@'); if (part.length === 2 && href) {