We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 27fd411 commit 1f8da8dCopy full SHA for 1f8da8d
2 files changed
src/uu/ptx/src/ptx.rs
@@ -788,7 +788,9 @@ fn write_traditional_output(
788
} else {
789
0
790
};
791
- config.line_width -= max_ref_len;
+
792
+ // Use saturating_sub to prevent panic if the reference is wider than the line width.
793
+ config.line_width = config.line_width.saturating_sub(max_ref_len);
794
}
795
796
for word_ref in words {
tests/by-util/test_ptx.rs
@@ -338,3 +338,12 @@ fn test_unicode_truncation_alignment() {
338
.succeeds()
339
.stdout_only(" / bar\n föö/\n");
340
341
342
+#[test]
343
+fn test_narrow_width_with_long_reference_no_panic() {
344
+ new_ucmd!()
345
+ .args(&["-w", "1", "-A"])
346
+ .pipe_in("content")
347
+ .succeeds()
348
+ .stdout_only(":1 content\n");
349
+}
0 commit comments