conflicts: don't panic when a conflict marker is missing removes

Closes #2611
This commit is contained in:
Martin von Zweigbergk 2024-09-05 09:03:58 -07:00 committed by Martin von Zweigbergk
parent 4f656f3e02
commit 3133534b32
3 changed files with 11 additions and 5 deletions

View file

@ -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

View file

@ -456,7 +456,7 @@ fn parse_conflict_hunk(input: &[u8]) -> Merge<BString> {
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<BString> {
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

View file

@ -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!(