From 15d696ae09a3c8185dd73dfd4edf40e6808e45ff Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 25 Oct 2024 23:42:20 +0300 Subject: [PATCH] hicli/sync: skip linkifying for messages with no special characters --- pkg/hicli/sync.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/hicli/sync.go b/pkg/hicli/sync.go index 467d996..fa8baae 100644 --- a/pkg/hicli/sync.go +++ b/pkg/hicli/sync.go @@ -383,10 +383,19 @@ func (h *HiClient) calculateLocalContent(ctx context.Context, dbEvt *database.Ev inlineImages = nil } } else { - var builder strings.Builder - builder.Grow(len(content.Body) + builderPreallocBuffer) - linkifyAndWriteBytes(&builder, []byte(content.Body)) - sanitizedHTML = builder.String() + hasSpecialCharacters := false + for _, char := range content.Body { + if char == '<' || char == '>' || char == '&' || char == '.' || char == ':' { + hasSpecialCharacters = true + break + } + } + if hasSpecialCharacters { + var builder strings.Builder + builder.Grow(len(content.Body) + builderPreallocBuffer) + linkifyAndWriteBytes(&builder, []byte(content.Body)) + sanitizedHTML = builder.String() + } wasPlaintext = true } return &database.LocalContent{