Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mentions being formatted with Markdown #2433

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Plastikmensch
Copy link

@Plastikmensch Plastikmensch commented Oct 6, 2023

Fixes #2432

Not the best solution, but the easiest I could think of not requiring a major refactor.
This will force escape underscores in mentions.

This will still not link correctly when content type is html, but I consider that a separate issue.

Prevents usernames with underscores being formatted with underline.

Signed-off-by: Plastikmensch <[email protected]>
Test that usernames with underscores get linked correctly

Signed-off-by: Plastikmensch <[email protected]>
@@ -98,7 +98,8 @@
private

def format_markdown(html)
html = markdown_formatter.render(html)
# Force escape usernames in mentions before formatting
html = markdown_formatter.render(html.gsub(Account::MENTION_RE) { |re| re.gsub('_', '\\_') })

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.
Copy link
Author

@Plastikmensch Plastikmensch Oct 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MENTION_RE doesn't match backslashes, so re cannot contain escaped underscores.
The reason escaping here works is because redcarpet converts escaped underscores to underscores instead of u elements before mentions are processed in rewrite
I haven't looked into why manually escaping usernames doesn't produce a mention, but I think that's expected behaviour.

@Plastikmensch Plastikmensch marked this pull request as ready for review October 6, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mentions gets rewritten as markdown
2 participants