mirror of
https://github.com/svemagie/indiekit-endpoint-activitypub.git
synced 2026-04-02 15:44:58 +02:00
fix(linkify): strip trailing punctuation from auto-linked URLs
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 <a> tag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,7 +32,12 @@ function linkifyUrls(html) {
|
|||||||
if (!html) return html;
|
if (!html) return html;
|
||||||
return html.replace(
|
return html.replace(
|
||||||
/(?<![=">])(https?:\/\/[^\s<"]+)/g,
|
/(?<![=">])(https?:\/\/[^\s<"]+)/g,
|
||||||
'<a href="$1">$1</a>',
|
(_, 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 `<a href="${clean}">${clean}</a>`;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1066,7 +1066,11 @@ function processStatusContent(content, rawText) {
|
|||||||
// Linkify bare URLs (http/https)
|
// Linkify bare URLs (http/https)
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
/(https?:\/\/[^\s<>"')\]]+)/g,
|
/(https?:\/\/[^\s<>"')\]]+)/g,
|
||||||
'<a href="$1" rel="nofollow noopener noreferrer" target="_blank">$1</a>',
|
(_, url) => {
|
||||||
|
// Strip trailing punctuation that is almost never part of a URL
|
||||||
|
const clean = url.replace(/[.,;:!?]+$/, "");
|
||||||
|
return `<a href="${clean}" rel="nofollow noopener noreferrer" target="_blank">${clean}</a>`;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert @user@domain mentions to profile links
|
// Convert @user@domain mentions to profile links
|
||||||
|
|||||||
Reference in New Issue
Block a user