glitch-soc / mastodon

A glitchy but lovable microblogging server
https://glitch-soc.github.io/docs/
GNU Affero General Public License v3.0
685 stars 182 forks source link

Links are parsed and truncated inside code blocks #1842

Open mxamber opened 1 year ago

mxamber commented 1 year ago

Steps to reproduce the problem

  1. Create a new toot
  2. Write a code block (inline or multi-line) and write a web address into it, such as https://example.com
  3. Send the toot

Expected behaviour

The link address should be displayed in full but not function as an actual link.

Actual behaviour

The http(s):// prefix is removed and the link is truncated if particularly long.

Specifications

Mastodon 3.5.2+glitch, occured specifically on eldritch.cafe (see here for examples).

See also: #1455 (links in code blocks create link previews)

single-right-quote commented 1 year ago

this still happens on 3.5.3+glitch, e.g., https://glitch.cat.family/@aescling/108910048909555291

(edit: just to make sure i tested again after recently merging in from Glitch and https://glitch.cat.family/@aescling/108952961487825158 shows this behavior still happens)

ClearlyClaire commented 1 year ago

Preventing such links from being crawled and generating a preview card may be difficult, as the link and mention detection happen on the raw text, and, for some edge cases, need to be able to modify it (so we can't just pass it through a markdown processor to remove code blocks entirely).

Not rewriting the link itself should be doable, although I'm not quite sure which part of the code causes that. In any case, that happens in https://github.com/glitch-soc/mastodon/blob/main/app/lib/advanced_text_formatter.rb but it could be from the markdown parser, or our rewrite (https://github.com/glitch-soc/mastodon/blob/main/app/lib/advanced_text_formatter.rb#L78) method. I think it may be the latter, in which case the best way to deal with that may be to change the regexp to skip code blocks.

I'm fairly busy with upstream work these days, so I might take a while to tackle this. In the meantime, PRs are welcome (though I'm not sure either how much time I can put in reviewing them).