fix: prevent side-by-side panic with narrow width or large tab width
When rendering a side-by-side diff, `SourceDimensions::new` could compute a per-column content width that was not greater than the tab width. That violates the precondition of `split_and_apply`, which asserts `max_len > tab_width` so it can always fit at least one expanded tab and make progress when wrapping. As a result difftastic aborted with a panic on ordinary input, for example `difft --width 14 a b` or, even at the default terminal width, `difft --tab-width 100 a b`. A very small `--width` could also drive the total display width down to two columns or fewer, underflowing the `display_width - SPACER.len()` subtraction (previously guarded by an assertion that itself aborted). Enforce both invariants in `SourceDimensions::new`: keep room for the column spacer, and ensure each content column is wider than the tab width. Narrow terminals now degrade gracefully instead of crashing.
This commit is contained in:
1 parent
32b79c1a63
commit
7f1f320438
2 files changed
+84
-7
No files matched your search
@@ -137,6 +137,28 @@ fn text_changes_at_end_doesnt_crash() {
|
||||
cmd.assert().success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn narrow_width_doesnt_crash() {
|
||||
let mut cmd = get_base_command();
|
||||
|
||||
cmd.arg("--width=14")
|
||||
.arg("sample_files/text_1.txt")
|
||||
.arg("sample_files/text_2.txt");
|
||||
|
||||
cmd.assert().success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn large_tab_width_doesnt_crash() {
|
||||
let mut cmd = get_base_command();
|
||||
|
||||
cmd.arg("--tab-width=100")
|
||||
.arg("sample_files/text_1.txt")
|
||||
.arg("sample_files/text_2.txt");
|
||||
|
||||
cmd.assert().success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn makefile_text_as_atom() {
|
||||
let mut cmd = get_base_command();
|
||||
|
||||
Reference in new issue
Block a user