Skip to content

Commit eaf8b1e

Browse files
sayrerclaude
andcommitted
Fix latent bug in hit highlighter with exhausted hits.
Replace unwrap_or(&(0, 0)) sentinel with if-let pattern matching. The sentinel value could spuriously match position 0 when all hits were consumed, leading to an out-of-bounds panic on the hits slice. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e0aa475 commit eaf8b1e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

rust/twitter-text/src/hit_highlighter.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ impl HitHighlighter {
5959
Rule::text => {
6060
let span = pair.as_span();
6161
for c in span.as_str().chars() {
62-
if builder.count() == hits.get(start).unwrap_or(&(0, 0)).0 {
63-
builder.append_open();
64-
tag_open = true;
65-
start += 1;
62+
if let Some(hit) = hits.get(start) {
63+
if builder.count() == hit.0 {
64+
builder.append_open();
65+
tag_open = true;
66+
start += 1;
67+
}
6668
}
6769
builder.append_char(c);
6870
if tag_open && builder.count() == hits[start - 1].1 {

0 commit comments

Comments
 (0)