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 <noreply@anthropic.com>
This commit is contained in:
@@ -345,7 +345,7 @@ fn collapse_newlines(s: &str) -> String {
|
|||||||
let mut result = String::with_capacity(s.len());
|
let mut result = String::with_capacity(s.len());
|
||||||
let mut prev_was_space = false;
|
let mut prev_was_space = false;
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
if c.is_ascii_whitespace() {
|
if c.is_whitespace() {
|
||||||
if !prev_was_space {
|
if !prev_was_space {
|
||||||
result.push(' ');
|
result.push(' ');
|
||||||
prev_was_space = true;
|
prev_was_space = true;
|
||||||
@@ -606,7 +606,13 @@ pub fn print_search_results_json(
|
|||||||
data: response,
|
data: response,
|
||||||
meta: SearchMeta { elapsed_ms },
|
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 {
|
if let Some(f) = fields {
|
||||||
let expanded = crate::cli::robot::expand_fields_preset(f, "search");
|
let expanded = crate::cli::robot::expand_fields_preset(f, "search");
|
||||||
crate::cli::robot::filter_fields(&mut value, "results", &expanded);
|
crate::cli::robot::filter_fields(&mut value, "results", &expanded);
|
||||||
|
|||||||
Reference in New Issue
Block a user