mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 14:12:31 +00:00
add quotes and escapes for necessary filenames
This commit is contained in:
parent
ebe7417a88
commit
d2e97e01bc
2 changed files with 11 additions and 2 deletions
|
@ -321,8 +321,7 @@ fn get_output(
|
|||
Block::Date => block_vec.push(meta.date.render(colors, flags)),
|
||||
Block::Name => {
|
||||
block_vec.extend([
|
||||
meta.name
|
||||
.render(colors, icons, display_option, flags.hyperlink),
|
||||
meta.name.render(colors, icons, display_option, flags.hyperlink),
|
||||
meta.indicator.render(flags),
|
||||
]);
|
||||
if !(flags.no_symlink.0 || flags.dereference.0 || flags.layout == Layout::Grid) {
|
||||
|
|
|
@ -79,6 +79,16 @@ impl Name {
|
|||
}
|
||||
|
||||
fn escape(&self, string: &str) -> String {
|
||||
let mut name = string.to_string();
|
||||
if name.contains('\\') || name.contains('"') {
|
||||
name = name.replace('\'', "\'\\\'\'");
|
||||
name = format!("\'{}\'", &name);
|
||||
} else if name.contains('\'') {
|
||||
name = format!("\"{}\"", &name);
|
||||
} else if name.contains(' ') || name.contains('$') {
|
||||
name = format!("\'{}\'", &name);
|
||||
}
|
||||
let string = name;
|
||||
if string
|
||||
.chars()
|
||||
.all(|c| c >= 0x20 as char && c != 0x7f as char)
|
||||
|
|
Loading…
Reference in a new issue