fix: UTF-8 Panic bei String-Truncation (db.rs + knowledge.rs) [appimage]
Some checks failed
Build AppImage / build (push) Failing after 3m34s
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:
parent
05bc35208d
commit
b9dfc8a720
2 changed files with 14 additions and 3 deletions
|
|
@ -717,7 +717,13 @@ impl Database {
|
||||||
let mut summary_parts: Vec<String> = Vec::new();
|
let mut summary_parts: Vec<String> = Vec::new();
|
||||||
for (_, role, content) in &old_messages {
|
for (_, role, content) in &old_messages {
|
||||||
let preview = if content.len() > 200 {
|
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 {
|
} else {
|
||||||
content.clone()
|
content.clone()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -993,9 +993,14 @@ pub async fn format_tool_hints(
|
||||||
|
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
hints.push(format!("\n**{}** ({})", entry.title, entry.category));
|
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 {
|
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 {
|
} else {
|
||||||
entry.content
|
entry.content
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue