diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 595dcc529..660ab4883 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -235,9 +235,20 @@ impl Sequence { ( l, if let Some(input) = a.strip_prefix('\\') { - char::from_u32(u32::from_str_radix(&input, 8).unwrap()).unwrap() + if input.is_empty() { + '\\' + } else { + char::from_u32( + u32::from_str_radix(&input, 8) + .expect("We only matched against 0-7 so it should not fail"), + ) + .expect("Cannot convert octal value to character") + } } else { - input.chars().next().unwrap() + input + .chars() + .next() + .expect("We recognized a character so this should not fail") }, ) }) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 99d7b5132..eb02eb962 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -112,6 +112,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 { return 1; } }; + + if set2.len() == 1 && set2[0] == '\\' { + show_error!( + "{}", + "warning: an unescaped backslash at end of string is not portable" + ); + } + if delete_flag { if squeeze_flag { let mut delete_buffer = vec![];