Skip to content

Commit

Permalink
ls: Escape dirname in recursive mode when it has a colon
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann authored and sylvestre committed Jul 18, 2024
1 parent 84f8b7a commit 571828a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2037,12 +2037,22 @@ impl PathData {
}

fn show_dir_name(path_data: &PathData, out: &mut BufWriter<Stdout>, config: &Config) {
if config.hyperlink && !config.dired {
let (name, has_colon) = if config.hyperlink && !config.dired {
let name = escape_name(path_data.p_buf.as_os_str(), &config.quoting_style);
let hyperlink = create_hyperlink(&name, path_data);
write!(out, "{}:", hyperlink).unwrap();
(hyperlink, name.contains(':'))
} else {
write!(out, "{}:", path_data.p_buf.display()).unwrap();
let name = path_data.p_buf.display().to_string();
let has_colon = name.contains(':');
(name, has_colon)
};

// if there is a colon in the dirname, add quotes to escape it.
// See https://github.com/uutils/coreutils/issues/6554
if has_colon {
write!(out, "'{}':", name).unwrap();
} else {
write!(out, "{}:", name).unwrap();
}
}

Expand Down Expand Up @@ -2327,9 +2337,10 @@ fn enter_directory(
for e in entries
.iter()
.skip(if config.files == Files::All { 2 } else { 0 })
.filter(|p| p.ft.get().is_some())
.filter(|p| p.ft.get().unwrap().is_some())
.filter(|p| p.ft.get().unwrap().unwrap().is_dir())
.filter(|p| {
p.ft.get()
.is_some_and(|o_ft| o_ft.is_some_and(|ft| ft.is_dir()))
})
{
match fs::read_dir(&e.p_buf) {
Err(err) => {
Expand Down

0 comments on commit 571828a

Please sign in to comment.