fix(text): avoid breaking UTF-8 during truncation

Use rune-aware truncation for user-facing text and log previews so multibyte content is not corrupted in memory context, Telegram messages, or diagnostics.
This commit is contained in:
BBQ
2026-03-08 16:29:38 +08:00
committed by 晨苒
parent c70d452238
commit 1bb90c70f4
8 changed files with 131 additions and 30 deletions
+2 -4
View File
@@ -19,6 +19,7 @@ import (
"github.com/memohai/memoh/internal/db"
"github.com/memohai/memoh/internal/db/sqlc"
"github.com/memohai/memoh/internal/textutil"
)
// OAuthService manages OAuth flows for MCP connections.
@@ -667,10 +668,7 @@ func parseTokenResponse(body []byte) (*tokenResponse, error) {
}
func truncate(s string, maxLen int) string {
if len(s) <= maxLen {
return s
}
return s[:maxLen] + "..."
return textutil.TruncateRunesWithSuffix(s, maxLen, "...")
}
func (s *OAuthService) refreshToken(ctx context.Context, tokenEndpoint, refreshToken, clientID, resourceURI string) (*tokenResponse, error) {