From 8ab65a340110b1c6834ecbbd758058a47d7a1d0a Mon Sep 17 00:00:00 2001 From: teernisse Date: Thu, 12 Mar 2026 17:07:05 -0400 Subject: [PATCH] fix(search): broaden whitespace collapse to all Unicode whitespace Change collapse_whitespace() from is_ascii_whitespace() to is_whitespace() so non-breaking spaces, em-spaces, and other Unicode whitespace characters in search snippets are also collapsed into single spaces. Additionally fix serde_json::to_value() call site to handle serialization errors gracefully instead of unwrapping. Co-Authored-By: Claude Opus 4.6 --- src/cli/commands/search.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/search.rs b/src/cli/commands/search.rs index a02ddb2..521bd92 100644 --- a/src/cli/commands/search.rs +++ b/src/cli/commands/search.rs @@ -345,7 +345,7 @@ fn collapse_newlines(s: &str) -> String { let mut result = String::with_capacity(s.len()); let mut prev_was_space = false; for c in s.chars() { - if c.is_ascii_whitespace() { + if c.is_whitespace() { if !prev_was_space { result.push(' '); prev_was_space = true; @@ -606,7 +606,13 @@ pub fn print_search_results_json( data: response, meta: SearchMeta { elapsed_ms }, }; - let mut value = serde_json::to_value(&output).unwrap(); + let mut value = match serde_json::to_value(&output) { + Ok(v) => v, + Err(e) => { + eprintln!("Error serializing search response: {e}"); + return; + } + }; if let Some(f) = fields { let expanded = crate::cli::robot::expand_fields_preset(f, "search"); crate::cli::robot::filter_fields(&mut value, "results", &expanded);