From bd3a623488f7b88817bf1b14f7733a4f40c7dcca Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Tue, 24 Mar 2026 19:56:49 +0100 Subject: [PATCH] fix(linkify): strip trailing punctuation from auto-linked URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URLs at the end of a sentence followed by . , ; : ) etc. were capturing the punctuation character as part of the URL, producing broken links (e.g. https://example.com. instead of https://example.com). Fix in both places where URL linkification happens: - lib/jf2-to-as2.js linkifyUrls() — used when federating posts via AP - lib/mastodon/routes/statuses.js processStatusContent() — used when creating posts via the Mastodon Client API Both now use a replacement callback that strips trailing [.,;:!?)\]'"] from the captured URL before inserting it into the tag. Co-Authored-By: Claude Sonnet 4.6 --- lib/jf2-to-as2.js | 7 ++++++- lib/mastodon/routes/statuses.js | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/jf2-to-as2.js b/lib/jf2-to-as2.js index 4168644..d5d402b 100644 --- a/lib/jf2-to-as2.js +++ b/lib/jf2-to-as2.js @@ -32,7 +32,12 @@ function linkifyUrls(html) { if (!html) return html; return html.replace( /(?])(https?:\/\/[^\s<"]+)/g, - '$1', + (_, url) => { + // Strip trailing punctuation that is almost never part of a URL + // e.g. "See https://example.com." → link to https://example.com + const clean = url.replace(/[.,;:!?)\]'"]+$/, ""); + return `${clean}`; + }, ); } diff --git a/lib/mastodon/routes/statuses.js b/lib/mastodon/routes/statuses.js index a074e72..7d39aa4 100644 --- a/lib/mastodon/routes/statuses.js +++ b/lib/mastodon/routes/statuses.js @@ -1066,7 +1066,11 @@ function processStatusContent(content, rawText) { // Linkify bare URLs (http/https) html = html.replace( /(https?:\/\/[^\s<>"')\]]+)/g, - '$1', + (_, url) => { + // Strip trailing punctuation that is almost never part of a URL + const clean = url.replace(/[.,;:!?]+$/, ""); + return `${clean}`; + }, ); // Convert @user@domain mentions to profile links