diff --git a/src/display.rs b/src/display.rs index 74788e4..edb37bc 100644 --- a/src/display.rs +++ b/src/display.rs @@ -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) { diff --git a/src/meta/name.rs b/src/meta/name.rs index 8bfa5d5..39e34f8 100644 --- a/src/meta/name.rs +++ b/src/meta/name.rs @@ -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)