mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
split: fix bug with large arguments to -C
Fix the behavior of `split -C` when given large arguments. Before this commit, bytes were being greedily assigned to a chunk too aggressively, leading to a situation where a split happened in the middle of a line even though the entire line could have fit within the next chunk. This was appearing for large arguments to `-C` and long lines that extended beyond the size of the read buffer. This commit fixes the behavior. Fixes #7026
This commit is contained in:
parent
54bc3cf944
commit
071e72ffc8
2 changed files with 126 additions and 216 deletions
|
@ -1973,3 +1973,20 @@ fn test_split_separator_same_multiple() {
|
|||
.args(&["-t:", "-t:", "-t,", "fivelines.txt"])
|
||||
.fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_long_lines() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let line1 = format!("{:131070}\n", "");
|
||||
let line2 = format!("{:1}\n", "");
|
||||
let line3 = format!("{:131071}\n", "");
|
||||
let infile = [line1, line2, line3].concat();
|
||||
ucmd.args(&["-C", "131072"])
|
||||
.pipe_in(infile)
|
||||
.succeeds()
|
||||
.no_output();
|
||||
assert_eq!(at.read("xaa").len(), 131_071);
|
||||
assert_eq!(at.read("xab").len(), 2);
|
||||
assert_eq!(at.read("xac").len(), 131_072);
|
||||
assert!(!at.plus("xad").exists());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue