Skip to content

Commit

Permalink
fix(indexing): Debugging nodes should respect utf8 char boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Sep 12, 2024
1 parent 501dd39 commit f95f806
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion swiftide-core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Debug for Node {
"chunk",
&format!(
"{} ({})",
&self.chunk.as_str()[..std::cmp::min(100, self.chunk.len())],
&self.chunk.chars().take(100).collect::<String>(),
self.chunk.chars().count()
),
)
Expand Down Expand Up @@ -270,4 +270,15 @@ mod tests {
assert_eq!(embedded_field.field_name(), expected[0]);
assert_eq!(embedded_field.sparse_field_name(), expected[1]);
}

#[test]
fn test_debugging_node_with_utf8_char_boundary() {
let node = Node::new("🦀".repeat(101));
// Single char
let _ = format!("{node:?}");

// With invalid char boundary
Node::new("Jürgen".repeat(100));
let _ = format!("{node:?}");
}
}

0 comments on commit f95f806

Please sign in to comment.