mastodon icon indicating copy to clipboard operation
mastodon copied to clipboard

ActivityPub `Mention` tags should support plain-text parsing properly

Open trwnh opened this issue 3 years ago • 1 comments

Steps to reproduce the problem

  1. Fetch a status mentioning a user, for example: https://mastodon.social/@pixelfed/108877020896668664.json

Expected behaviour

mention substring in content should match name in tag

Actual behaviour

it does not match

Specifications

https://github.com/mastodon/mastodon/blob/07f8b4d1b19f734d04e69daeb4c3421ef9767aac/app/serializers/activitypub/note_serializer.rb#L240-L254

the Mention serializer is hardcoded to use acct but the HTML in Note.content does not match this. For local users it is fine, since @trwnh in Note.content matches @trwnh in Mention.name. But for remote users, Note.content contains @gmate8 and Mention.name contains @[email protected], which do not match. this prevents plain-text parsing whenever any remote user is mentioned.

this can be fixed either by changing Mention.name to use username, or changing Note.content to use the full acct in mentions, perhaps with an invisible span around the domain part? regardless of which solution is picked, Mention.name should be a substring of Note.content.


tangentially, one other thing i have to ask about is that i noticed Mention.href uses uri instead of a url. Are there any technical reasons for this? I would expect the Mention.href to match the a.href as well...

trwnh avatar Sep 01 '22 10:09 trwnh

i think i've identified the relevant code introduced by #17828

https://github.com/mastodon/mastodon/blob/95a149d7c12666d15257ac88687b3193a74179c1/app/lib/text_formatter.rb#L97-L127

the html returned makes a reference to display_username:

https://github.com/mastodon/mastodon/blob/95a149d7c12666d15257ac88687b3193a74179c1/app/lib/text_formatter.rb#L125

display_username is defined here:

https://github.com/mastodon/mastodon/blob/95a149d7c12666d15257ac88687b3193a74179c1/app/lib/text_formatter.rb#L122

it looks like it depends on a parameter with_domains:

https://github.com/mastodon/mastodon/blob/95a149d7c12666d15257ac88687b3193a74179c1/app/lib/text_formatter.rb#L143-L145

i am not sure where this parameter gets added or not...

trwnh avatar Sep 03 '22 10:09 trwnh