fix: UTF-8 Panic bei String-Truncation (db.rs + knowledge.rs) [appimage]
Some checks failed
Build AppImage / build (push) Failing after 3m34s

Crash: "byte index 200 is not a char boundary; inside '─' (bytes 198..201)"
Fix: char_indices() statt byte-slice für sicheres Abschneiden bei
Multi-Byte-Zeichen (ä, ü, ─, etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eddy 2026-04-21 13:49:21 +02:00
parent 05bc35208d
commit b9dfc8a720
2 changed files with 14 additions and 3 deletions

View file

@ -717,7 +717,13 @@ impl Database {
let mut summary_parts: Vec<String> = Vec::new();
for (_, role, content) in &old_messages {
let preview = if content.len() > 200 {
format!("{}...", &content[..200])
// Sicher an Char-Boundary abschneiden (Multi-Byte wie ─, ä, ü)
let end = content.char_indices()
.take_while(|(i, _)| *i < 200)
.last()
.map(|(i, c)| i + c.len_utf8())
.unwrap_or(200.min(content.len()));
format!("{}...", &content[..end])
} else {
content.clone()
};

View file

@ -993,9 +993,14 @@ pub async fn format_tool_hints(
for entry in entries {
hints.push(format!("\n**{}** ({})", entry.title, entry.category));
// Content auf ~300 Zeichen kürzen
// Content auf ~300 Zeichen kürzen (sicher an Char-Boundary)
let content = if entry.content.len() > 300 {
format!("{}...", &entry.content[..300])
let end = entry.content.char_indices()
.take_while(|(i, _)| *i < 300)
.last()
.map(|(i, c)| i + c.len_utf8())
.unwrap_or(300.min(entry.content.len()));
format!("{}...", &entry.content[..end])
} else {
entry.content
};