Fixed empty backslash

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
This commit is contained in:
Hanif Bin Ariffin 2021-07-29 21:59:30 +08:00
parent 36c19293c8
commit 4fb4511da3
2 changed files with 21 additions and 2 deletions

View file

@ -235,9 +235,20 @@ impl Sequence {
( (
l, l,
if let Some(input) = a.strip_prefix('\\') { 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 { } else {
input.chars().next().unwrap() input
.chars()
.next()
.expect("We recognized a character so this should not fail")
}, },
) )
}) })

View file

@ -112,6 +112,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
return 1; 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 delete_flag {
if squeeze_flag { if squeeze_flag {
let mut delete_buffer = vec![]; let mut delete_buffer = vec![];