From 76a2f2128bec048bd3d77259585ffbcb56572d10 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 29 Mar 2024 00:50:33 +0100 Subject: [PATCH 1/2] tr: guard against regressions of class [:space:] --- tests/by-util/test_tr.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 6adbc4022..c2f69014a 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1283,3 +1283,19 @@ fn test_complement_flag_fails_with_more_than_two_operand() { .fails() .stderr_contains("extra operand 'c'"); } + +#[test] +fn check_regression_class_space() { + // This invocation checks: + // 1. that the [:space:] class has exactly 6 characters, + // 2. that the [:space:] class contains at least the given 6 characters (and therefore no other characters), and + // 3. that the given characters occur in exactly this order. + new_ucmd!() + .args(&["[:space:][:upper:]", "123456[:lower:]"]) + // 0x0B = "\v" ("VERTICAL TAB") + // 0x0C = "\f" ("FEED FORWARD") + .pipe_in("A\t\n\u{0B}\u{0C}\r B") + .succeeds() + .no_stderr() + .stdout_only("a123456b"); +} From e9045be593b2b4ab9559993d0233e283be78ef92 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 29 Mar 2024 00:55:34 +0100 Subject: [PATCH 2/2] tr: fix order inside class [:blank:] --- src/uu/tr/src/unicode_table.rs | 2 +- tests/by-util/test_tr.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/uu/tr/src/unicode_table.rs b/src/uu/tr/src/unicode_table.rs index 5d31ab375..06687c392 100644 --- a/src/uu/tr/src/unicode_table.rs +++ b/src/uu/tr/src/unicode_table.rs @@ -12,4 +12,4 @@ pub static FF: u8 = 0xC; pub static CR: u8 = 0xD; pub static SPACE: u8 = 0x20; pub static SPACES: &[u8] = &[HT, LF, VT, FF, CR, SPACE]; -pub static BLANK: &[u8] = &[SPACE, HT]; +pub static BLANK: &[u8] = &[HT, SPACE]; diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index c2f69014a..2502031b1 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1299,3 +1299,17 @@ fn check_regression_class_space() { .no_stderr() .stdout_only("a123456b"); } + +#[test] +fn check_regression_class_blank() { + // This invocation checks: + // 1. that the [:blank:] class has exactly 2 characters, + // 2. that the [:blank:] class contains at least the given 2 characters (and therefore no other characters), and + // 3. that the given characters occur in exactly this order. + new_ucmd!() + .args(&["[:blank:][:upper:]", "12[:lower:]"]) + .pipe_in("A\t B") + .succeeds() + .no_stderr() + .stdout_only("a12b"); +}