From 9a01062ae248327e62c478fd2ec5bd7518ea4f0b Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 30 Apr 2024 12:51:30 +0200 Subject: [PATCH] Fix user mention processing When mentioning a user, the markup post-processor did not handle the case where the mentioned user did not exist well: it tried to skip to the next node, which in turn, ended up skipping the rest of the line. To fix this, lets skip just the mentioned, but non-existing user, and continue processing the current node from there. Fixes #3535. Signed-off-by: Gergely Nagy --- modules/markup/html.go | 4 ++-- modules/templates/util_render_test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 7a5ca14aeb..56f63b8a76 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -623,10 +623,10 @@ func mentionProcessor(ctx *RenderContext, node *html.Node) { if DefaultProcessorHelper.IsUsernameMentionable != nil && DefaultProcessorHelper.IsUsernameMentionable(ctx.Ctx, mentionedUsername) { replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(ctx.Links.Prefix(), mentionedUsername), mention, "mention")) node = node.NextSibling.NextSibling + start = 0 } else { - node = node.NextSibling + start = loc.End } - start = 0 } } diff --git a/modules/templates/util_render_test.go b/modules/templates/util_render_test.go index c1d5e26f62..ea01612ac3 100644 --- a/modules/templates/util_render_test.go +++ b/modules/templates/util_render_test.go @@ -50,6 +50,11 @@ func TestApostrophesInMentions(t *testing.T) { assert.EqualValues(t, template.HTML("

@mention-user's comment

\n"), rendered) } +func TestNonExistantUserMention(t *testing.T) { + rendered := RenderMarkdownToHtml(context.Background(), "@ThisUserDoesNotExist @mention-user") + assert.EqualValues(t, template.HTML("

@ThisUserDoesNotExist @mention-user

\n"), rendered) +} + func TestRenderCommitBody(t *testing.T) { type args struct { ctx context.Context