mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Fix cut
when lines dont end with specified delim (#5844)
Print lines without delimiters only when they end with specified line terminator('\n' by default or `\0` if `-s`) Signed-off-by: Andrei Stan <andreistan2003@gmail.com> Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
parent
17d4e4fde1
commit
5b087e9624
2 changed files with 10 additions and 4 deletions
|
@ -213,11 +213,8 @@ fn cut_fields_implicit_out_delim<R: Read, M: Matcher>(
|
||||||
let mut print_delim = false;
|
let mut print_delim = false;
|
||||||
|
|
||||||
if delim_search.peek().is_none() {
|
if delim_search.peek().is_none() {
|
||||||
if !only_delimited {
|
if !only_delimited && line[line.len() - 1] == newline_char {
|
||||||
out.write_all(line)?;
|
out.write_all(line)?;
|
||||||
if line[line.len() - 1] != newline_char {
|
|
||||||
out.write_all(&[newline_char])?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
|
|
|
@ -282,6 +282,15 @@ fn test_multiple() {
|
||||||
assert_eq!(result.stderr_str(), "");
|
assert_eq!(result.stderr_str(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_newline_delimited() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-f", "1", "-d", "\n"])
|
||||||
|
.pipe_in("a:1\nb:")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only_bytes("a:1\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multiple_mode_args() {
|
fn test_multiple_mode_args() {
|
||||||
for args in [
|
for args in [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue