Skip to main content

max / makenotwork

Fix search query panic on multi-byte UTF-8 truncation Use is_char_boundary to find safe truncation point instead of slicing at byte 200. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author: Max J. <87768334+MaxJMath@users.noreply.github.com> · 2026-04-26 20:06 UTC
Commit: c3956c138ba6f0328ebcba81d7c1dd19fb3c85df
Parent: 8ae68e6
1 file changed, +8 insertions, -2 deletions
@@ -28,8 +28,14 @@ pub(super) async fn search_handler(
28 28 return Ok(SearchResultsFragment { results: vec![] });
29 29 }
30 30
31 - // Sanitize: limit length
32 - let q = if q.len() > 200 { &q[..200] } else { q };
31 + // Sanitize: limit length (find a char boundary to avoid UTF-8 panic)
32 + let q = if q.len() > 200 {
33 + let mut end = 200;
34 + while !q.is_char_boundary(end) { end -= 1; }
35 + &q[..end]
36 + } else {
37 + q
38 + };
33 39
34 40 let scope = query.scope.as_deref().filter(|s| !s.is_empty());
35 41