From e1626b8c64202d70f8269aafce885a952007671f Mon Sep 17 00:00:00 2001 From: Michael Kefeder Date: Fri, 12 Mar 2021 21:52:37 +0100 Subject: [PATCH 1/3] ptx: ignore empty regex (#1808) * ptx: ignore empty -W regex * ptx: test to verify empty -W regex is ignored * tests/ptx: verify word regexp from cmd-line is used --- src/uu/ptx/src/ptx.rs | 19 ++++++++++++++----- tests/by-util/test_ptx.rs | 16 ++++++++++++++++ ...roff_no_ref_word_regexp_exc_space.expected | 7 +++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/ptx/gnu_ext_disabled_roff_no_ref_word_regexp_exc_space.expected diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 8421e52bc..bfcd6699f 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -95,12 +95,21 @@ impl WordFilter { if matches.opt_present("b") { crash!(1, "-b not implemented yet"); } - let reg = if matches.opt_present("W") { - matches.opt_str("W").expect("parsing options failed!") - } else if config.gnu_ext { - "\\w+".to_owned() + // Ignore empty string regex from cmd-line-args + let arg_reg: Option = if matches.opt_present("W") { + matches.opt_str("W").filter(|reg| !reg.is_empty()) } else { - "[^ \t\n]+".to_owned() + None + }; + let reg = match arg_reg { + Some(arg_reg) => arg_reg, + None => { + if config.gnu_ext { + "\\w+".to_owned() + } else { + "[^ \t\n]+".to_owned() + } + } }; WordFilter { only_specified: o, diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 77117c5c0..e44943bfa 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -8,6 +8,22 @@ fn gnu_ext_disabled_roff_no_ref() { .stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected"); } +#[test] +fn gnu_ext_disabled_roff_no_ref_empty_word_regexp() { + new_ucmd!() + .args(&["-G", "-R", "-W", "", "input"]) + .succeeds() + .stdout_only_fixture("gnu_ext_disabled_roff_no_ref.expected"); +} + +#[test] +fn gnu_ext_disabled_roff_no_ref_word_regexp_exc_space() { + new_ucmd!() + .args(&["-G", "-R", "-W", "[^\t\n]+", "input"]) + .succeeds() + .stdout_only_fixture("gnu_ext_disabled_roff_no_ref_word_regexp_exc_space.expected"); +} + #[test] fn gnu_ext_disabled_roff_input_ref() { new_ucmd!() diff --git a/tests/fixtures/ptx/gnu_ext_disabled_roff_no_ref_word_regexp_exc_space.expected b/tests/fixtures/ptx/gnu_ext_disabled_roff_no_ref_word_regexp_exc_space.expected new file mode 100644 index 000000000..141e6c9f8 --- /dev/null +++ b/tests/fixtures/ptx/gnu_ext_disabled_roff_no_ref_word_regexp_exc_space.expected @@ -0,0 +1,7 @@ +.xx "" "" """quotes"", for roff" "" +.xx "" "" "and some other like %a, b#, c$c" "" +.xx "" "" "hello world!" "" +.xx "" "" "let's check special characters:" "" +.xx "" "" "maybe also~or^" "" +.xx "" "" "oh, and back\slash" "" +.xx "" "" "{brackets} for tex" "" From 47f50a0f5f244eb48c642d3ea9731eac20312731 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Fri, 12 Mar 2021 22:26:27 +0100 Subject: [PATCH 2/3] tests/utils: fixed mode for write (#1802) added `log_info` --- tests/common/util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/common/util.rs b/tests/common/util.rs index 92e5b9128..0f1acd49a 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -261,6 +261,7 @@ impl AtPath { } pub fn write(&self, name: &str, contents: &str) { + log_info("open(write)", self.plus_as_string(name)); let _ = std::fs::write(self.plus(name), contents); } From cd4003007f447a6cb61a41cb799e30fbc3c092ac Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 12 Mar 2021 23:10:12 +0100 Subject: [PATCH 3/3] refresh cargo.lock with updates --- Cargo.lock | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe9e11c35..edddc56e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,7 +193,7 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.85 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -404,7 +404,7 @@ dependencies = [ "oorandom 11.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "plotters 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.124 (registry+https://github.com/rust-lang/crates.io-index)", "serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.124 (registry+https://github.com/rust-lang/crates.io-index)", @@ -517,7 +517,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1035,13 +1035,12 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.3" +version = "1.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.23 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1054,7 +1053,7 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1472,7 +1471,7 @@ version = "0.0.4" dependencies = [ "getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.7", "uucore_procs 0.0.5", @@ -1635,8 +1634,8 @@ dependencies = [ "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.85 (registry+https://github.com/rust-lang/crates.io-index)", "md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.23 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1837,8 +1836,8 @@ dependencies = [ "getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.85 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.23 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.7", "uucore_procs 0.0.5", ] @@ -1938,8 +1937,8 @@ dependencies = [ "getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.85 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.23 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.7", "uucore_procs 0.0.5", ] @@ -2597,9 +2596,9 @@ dependencies = [ "checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" "checksum redox_syscall 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" "checksum redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" -"checksum regex 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +"checksum regex 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "54fd1046a3107eb58f42de31d656fee6853e5d276c455fd943742dce89fc3dd3" "checksum regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -"checksum regex-syntax 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" +"checksum regex-syntax 0.6.23 (registry+https://github.com/rust-lang/crates.io-index)" = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" "checksum remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" "checksum rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"