diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b01eb3ba9..abb70b6da4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed bugs + * Fixed panic when parsing invalid conflict markers of a particular form. + ([#2611](https://github.com/martinvonz/jj/pull/2611)) + ## [0.21.0] - 2024-09-04 ### Breaking changes diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 8050971857..f1bdf72c54 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -456,7 +456,7 @@ fn parse_conflict_hunk(input: &[u8]) -> Merge { removes.last_mut().unwrap().extend_from_slice(rest); adds.last_mut().unwrap().extend_from_slice(rest); } else { - // Doesn't look like a conflict + // Doesn't look like a valid conflict return Merge::resolved(BString::new(vec![])); } } @@ -467,13 +467,18 @@ fn parse_conflict_hunk(input: &[u8]) -> Merge { adds.last_mut().unwrap().extend_from_slice(line); } State::Unknown => { - // Doesn't look like a conflict + // Doesn't look like a valid conflict return Merge::resolved(BString::new(vec![])); } } } - Merge::from_removes_adds(removes, adds) + if adds.len() == removes.len() + 1 { + Merge::from_removes_adds(removes, adds) + } else { + // Doesn't look like a valid conflict + Merge::resolved(BString::new(vec![])) + } } /// Parses conflict markers in `content` and returns an updated version of diff --git a/lib/tests/test_conflicts.rs b/lib/tests/test_conflicts.rs index 248739dac0..e5d23a530b 100644 --- a/lib/tests/test_conflicts.rs +++ b/lib/tests/test_conflicts.rs @@ -750,8 +750,6 @@ fn test_parse_conflict_wrong_arity() { } #[test] -// TODO: Should *not* panic -#[should_panic] fn test_parse_conflict_malformed_missing_removes() { // Right number of adds but missing removes assert_eq!(