From 74beb208f84ac2a7f7738e1496d11d78715fb016 Mon Sep 17 00:00:00 2001 From: Misakait Date: Thu, 2 Oct 2025 04:26:23 +0800 Subject: [PATCH 1/2] fix(ptx): Remove extra space before truncation marker and a regression test (`test_truncation_no_extra_space_in_after`) has been added. Close#8783 --- src/uu/ptx/src/ptx.rs | 2 +- tests/by-util/test_ptx.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 930d4773ec0..95a1a58ce66 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -403,7 +403,7 @@ fn trim_idx(s: &[char], beg: usize, end: usize) -> (usize, usize) { while b < e && s[b].is_whitespace() { b += 1; } - while b < e && s[e - 1].is_whitespace() { + while beg < e && s[e - 1].is_whitespace() { e -= 1; } (b, e) diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 386ca9d8bfe..e529590948f 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -11,6 +11,15 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails_with_code(1); } +#[test] +fn test_truncation_no_extra_space_in_after() { + new_ucmd!() + .args(&["-G", "-w", "30"]) + .pipe_in("Rust is funnnnnnnnnnnnnnnnn") + .succeeds() + .stdout_contains(".xx \"\" \"Rust\" \"is/\" \"\""); +} + #[test] fn gnu_ext_disabled_rightward_no_ref() { new_ucmd!() From 3f823f4c3cd790c1eac11155f48832f948e1ce2f Mon Sep 17 00:00:00 2001 From: Misakait Date: Thu, 2 Oct 2025 04:26:23 +0800 Subject: [PATCH 2/2] fix(ptx): Remove extra space before truncation marker and a regression test (`test_truncation_no_extra_space_in_after`) has been added. Close#8783 --- src/uu/ptx/src/ptx.rs | 2 +- tests/by-util/test_ptx.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 930d4773ec0..95a1a58ce66 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -403,7 +403,7 @@ fn trim_idx(s: &[char], beg: usize, end: usize) -> (usize, usize) { while b < e && s[b].is_whitespace() { b += 1; } - while b < e && s[e - 1].is_whitespace() { + while beg < e && s[e - 1].is_whitespace() { e -= 1; } (b, e) diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 386ca9d8bfe..426792e054e 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // spell-checker:ignore roff - +// spell-checker:ignore funnnnnnnnnnnnnnnnn use uutests::new_ucmd; #[test] @@ -11,6 +11,15 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails_with_code(1); } +#[test] +fn test_truncation_no_extra_space_in_after() { + new_ucmd!() + .args(&["-G", "-w", "30"]) + .pipe_in("Rust is funnnnnnnnnnnnnnnnn") + .succeeds() + .stdout_contains(".xx \"\" \"Rust\" \"is/\" \"\""); +} + #[test] fn gnu_ext_disabled_rightward_no_ref() { new_ucmd!()