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 @@ -788,7 +788,9 @@ fn write_traditional_output(
788788 } else {
789789 0
790790 } ;
791- config. line_width -= max_ref_len;
791+
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) ;
792794 }
793795
794796 for word_ref in words {
Original file line number Diff line number Diff line change @@ -338,3 +338,12 @@ fn test_unicode_truncation_alignment() {
338338 . succeeds ( )
339339 . stdout_only ( " / bar\n föö/\n " ) ;
340340}
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+ }
You can’t perform that action at this time.
0 commit comments