mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix(ptx): Prevent text chunks from over-reading at boundaries
Fixes a bug in `get_output_chunks` where calculated text chunks (e.g., `tail`) would incorrectly include a trailing space and the first character of the next word. The fix explicitly checks for and trims this pattern to ensure chunk boundaries are respected, matching GNU ptx behavior.
This commit is contained in:
committed by
Daniel Hofstetter
parent
bdd8939d1b
commit
6327810b03
+12
-1
@@ -484,7 +484,18 @@ fn get_output_chunks(
|
||||
let tail_end = trim_broken_word_right(all_after, tail_beg, tail_end);
|
||||
|
||||
// trim away whitespace again.
|
||||
let (tail_beg, tail_end) = trim_idx(all_after, tail_beg, tail_end);
|
||||
let (tail_beg, mut tail_end) = trim_idx(all_after, tail_beg, tail_end);
|
||||
// Fix: Manually trim trailing char (like "a") that are preceded by a space.
|
||||
// This handles cases like "is a" which are not correctly trimmed by the
|
||||
// preceding functions.
|
||||
if tail_end >= 2
|
||||
&& (tail_end - 2) > tail_beg
|
||||
&& all_after[tail_end - 2].is_whitespace()
|
||||
&& !all_after[tail_end - 1].is_whitespace()
|
||||
{
|
||||
tail_end -= 1;
|
||||
(_, tail_end) = trim_idx(all_after, tail_beg, tail_end);
|
||||
}
|
||||
|
||||
// and get the string
|
||||
let tail_str: String = all_after[tail_beg..tail_end].iter().collect();
|
||||
|
||||
Reference in New Issue
Block a user