From 3bf99b8a4a5211c35cac421c2f513068661ee250 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 27 Oct 2025 19:19:52 +0100 Subject: [PATCH] Fix URL comparison for mentions in case of empty path (#36613) --- .../mastodon/components/status_content.jsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/components/status_content.jsx b/app/javascript/mastodon/components/status_content.jsx index a6ce8050c2..cef2be6281 100644 --- a/app/javascript/mastodon/components/status_content.jsx +++ b/app/javascript/mastodon/components/status_content.jsx @@ -72,6 +72,17 @@ const mapStateToProps = state => ({ languages: state.getIn(['server', 'translationLanguages', 'items']), }); +const compareUrls = (href1, href2) => { + try { + const url1 = new URL(href1); + const url2 = new URL(href2); + + return url1.origin === url2.origin && url1.path === url2.path && url1.search === url2.search; + } catch { + return false; + } +}; + class StatusContent extends PureComponent { static propTypes = { identity: identityContextPropShape, @@ -127,7 +138,7 @@ class StatusContent extends PureComponent { link.classList.add('status-link'); - mention = this.props.status.get('mentions').find(item => link.href === item.get('url')); + mention = this.props.status.get('mentions').find(item => compareUrls(link, item.get('url'))); if (mention) { link.addEventListener('click', this.onMentionClick.bind(this, mention), false); @@ -206,7 +217,7 @@ class StatusContent extends PureComponent { handleElement = (element, { key, ...props }, children) => { if (element instanceof HTMLAnchorElement) { - const mention = this.props.status.get('mentions').find(item => element.href === item.get('url')); + const mention = this.props.status.get('mentions').find(item => compareUrls(element.href, item.get('url'))); return (