File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -747,7 +747,9 @@ fn write_traditional_output(
747747 } else {
748748 0
749749 } ;
750- config. line_width -= max_ref_len;
750+
751+ // Use saturating_sub to prevent panic if the reference is wider than the line width.
752+ config. line_width = config. line_width . saturating_sub ( max_ref_len) ;
751753 }
752754
753755 for word_ref in words {
Original file line number Diff line number Diff line change @@ -301,3 +301,12 @@ fn test_unicode_truncation_alignment() {
301301 . succeeds ( )
302302 . stdout_only ( " / bar\n föö/\n " ) ;
303303}
304+
305+ #[ test]
306+ fn test_narrow_width_with_long_reference_no_panic ( ) {
307+ new_ucmd ! ( )
308+ . args ( & [ "-w" , "1" , "-A" ] )
309+ . pipe_in ( "content" )
310+ . succeeds ( )
311+ . stdout_only ( ":1 content\n " ) ;
312+ }
You can’t perform that action at this time.
0 commit comments