diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index c273b976c..c3bedb266 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -31,6 +31,8 @@ const ABOUT: &str = "\ Mandatory arguments to long options are mandatory for short options too.\n\ With no FILE, or when FILE is -, read standard input. Default is '-F /'."; +const REGEX_CHARCLASS: &str = "^-]\\"; + #[derive(Debug)] enum OutFormat { Dumb, @@ -166,7 +168,11 @@ impl WordFilter { break_set .unwrap() .into_iter() - .map(|c| c.to_string()) + .map(|c| if REGEX_CHARCLASS.contains(c) { + format!("\\{}", c) + } else { + c.to_string() + }) .collect::>() .join("") ) diff --git a/tests/fixtures/ptx/break_file b/tests/fixtures/ptx/break_file index 4c992d40a..499598c20 100644 --- a/tests/fixtures/ptx/break_file +++ b/tests/fixtures/ptx/break_file @@ -1 +1 @@ -abc_e +abc_e^-]\ diff --git a/tests/fixtures/ptx/gnu_ext_disabled_break_file.expected b/tests/fixtures/ptx/gnu_ext_disabled_break_file.expected index 7afce1861..7ea13471d 100644 --- a/tests/fixtures/ptx/gnu_ext_disabled_break_file.expected +++ b/tests/fixtures/ptx/gnu_ext_disabled_break_file.expected @@ -29,6 +29,7 @@ .xx "" "let's check special characte" "rs:" "" .xx "" """quote" "s"", for roff" "" .xx "" "oh, and back\sla" "sh" "" +.xx "" "oh, and back\" "slash" "" .xx "" "and" "some other like %a, b#, c$c" "" .xx "" "let's check" "special characters:" "" .xx "" "let's check special charac" "ters:" ""