From 1e17bac9f0e985b975ad5046781a558de51e033b Mon Sep 17 00:00:00 2001 From: zeo Date: Fri, 13 Feb 2026 21:38:14 +0800 Subject: [PATCH] fix: correct index bug in extractCodeBlocks and extractInlineCodes The previous implementation used len(codes)-1 in ReplaceAllStringFunc, which caused all placeholders to point to the same (last) index. This resulted in only the last code block being displayed correctly when multiple code blocks were present in a message. Now using a proper counter variable that increments for each match, ensuring each code block gets a unique placeholder index. --- pkg/channels/telegram.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index 3ad4818..3e1c40e 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -470,8 +470,11 @@ func extractCodeBlocks(text string) codeBlockMatch { codes = append(codes, match[1]) } + i := 0 text = re.ReplaceAllStringFunc(text, func(m string) string { - return fmt.Sprintf("\x00CB%d\x00", len(codes)-1) + placeholder := fmt.Sprintf("\x00CB%d\x00", i) + i++ + return placeholder }) return codeBlockMatch{text: text, codes: codes} @@ -491,8 +494,11 @@ func extractInlineCodes(text string) inlineCodeMatch { codes = append(codes, match[1]) } + i := 0 text = re.ReplaceAllStringFunc(text, func(m string) string { - return fmt.Sprintf("\x00IC%d\x00", len(codes)-1) + placeholder := fmt.Sprintf("\x00IC%d\x00", i) + i++ + return placeholder }) return inlineCodeMatch{text: text, codes: codes}