From 8fb387dbc30ebbb44cd937e45097e50d6f49f24b Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Tue, 10 Feb 2026 00:14:48 +0000 Subject: [PATCH] Fix panic in zeta1 prompt parsing (#48822) (cherry-pick to preview) (#48831) Cherry-pick of #48822 to preview ---- Closes #48712 - [ ] Tests or screenshots needed? - [ ] Code Reviewed - [ ] Manual QA Release Notes: - Fixed a panic when parsing predictions made by zeta1 Co-authored-by: Ben Kunkle --- crates/edit_prediction/src/zeta1.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/edit_prediction/src/zeta1.rs b/crates/edit_prediction/src/zeta1.rs index c7b093edec197f6e161e755f8fd3c429528badfc..3ab56d77280981197b0fb289cbca28f9e98b41ff 100644 --- a/crates/edit_prediction/src/zeta1.rs +++ b/crates/edit_prediction/src/zeta1.rs @@ -330,7 +330,8 @@ pub(crate) fn parse_edits( .map(|e| e.0.saturating_sub(1)) // -1 to exclude \n before marker .unwrap_or(content.strip_suffix("\n").unwrap_or(&content).len()); - let new_text = &content[content_start..content_end]; + // if there is a single newline between markers, content_start will be 1 more than content_end. .min ensures empty slice in that case + let new_text = &content[content_start.min(content_end)..content_end]; let old_text = snapshot .text_for_range(editable_range.clone()) @@ -722,4 +723,19 @@ mod tests { ```"#} ); } + + #[gpui::test] + fn test_parse_edits_empty_editable_region(cx: &mut App) { + let text = "fn foo() {\n let x = 42;\n}\n"; + let buffer = cx.new(|cx| Buffer::local(text, cx)); + let snapshot = buffer.read(cx).snapshot(); + + let output = "<|editable_region_start|>\n<|editable_region_end|>"; + let editable_range = 0..text.len(); + let edits = parse_edits(output, editable_range, &snapshot).unwrap(); + assert_eq!(edits.len(), 1); + let (range, new_text) = &edits[0]; + assert_eq!(range.to_offset(&snapshot), 0..text.len(),); + assert_eq!(new_text.as_ref(), ""); + } }