Skip to content

Commit 1e80d3e

Browse files
authored
ls: fix error sub dir output (#6521)
Closes #6492
1 parent a18c132 commit 1e80d3e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/uu/ls/src/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ impl PathData {
20382038

20392039
fn show_dir_name(path_data: &PathData, out: &mut BufWriter<Stdout>, config: &Config) {
20402040
if config.hyperlink && !config.dired {
2041-
let name = escape_name(&path_data.display_name, &config.quoting_style);
2041+
let name = escape_name(path_data.p_buf.as_os_str(), &config.quoting_style);
20422042
let hyperlink = create_hyperlink(&name, path_data);
20432043
write!(out, "{}:", hyperlink).unwrap();
20442044
} else {

tests/by-util/test_ls.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,6 +4594,49 @@ fn test_ls_hyperlink_dirs() {
45944594
.contains(&format!("{path}{separator}{dir_b}\x07{dir_b}\x1b]8;;\x07:")));
45954595
}
45964596

4597+
#[test]
4598+
fn test_ls_hyperlink_recursive_dirs() {
4599+
let scene = TestScenario::new(util_name!());
4600+
let at = &scene.fixtures;
4601+
let path = at.root_dir_resolved();
4602+
let separator = std::path::MAIN_SEPARATOR_STR;
4603+
4604+
let dir_a = "a";
4605+
let dir_b = "b";
4606+
at.mkdir(dir_a);
4607+
at.mkdir(format!("{dir_a}/{dir_b}"));
4608+
4609+
let result = scene
4610+
.ucmd()
4611+
.arg("--hyperlink")
4612+
.arg("--recursive")
4613+
.arg(dir_a)
4614+
.succeeds();
4615+
4616+
macro_rules! assert_hyperlink {
4617+
($line:expr, $expected:expr) => {
4618+
assert!(matches!($line, Some(l) if l.starts_with("\x1b]8;;file://") && l.ends_with($expected)));
4619+
};
4620+
}
4621+
4622+
let mut lines = result.stdout_str().lines();
4623+
assert_hyperlink!(
4624+
lines.next(),
4625+
&format!("{path}{separator}{dir_a}\x07{dir_a}\x1b]8;;\x07:")
4626+
);
4627+
assert_hyperlink!(
4628+
lines.next(),
4629+
&format!("{path}{separator}{dir_a}{separator}{dir_b}\x07{dir_b}\x1b]8;;\x07")
4630+
);
4631+
assert!(matches!(lines.next(), Some(l) if l.is_empty()));
4632+
assert_hyperlink!(
4633+
lines.next(),
4634+
&format!(
4635+
"{path}{separator}{dir_a}{separator}{dir_b}\x07{dir_a}{separator}{dir_b}\x1b]8;;\x07:"
4636+
)
4637+
);
4638+
}
4639+
45974640
#[test]
45984641
fn test_ls_color_do_not_reset() {
45994642
let scene: TestScenario = TestScenario::new(util_name!());

0 commit comments

Comments
 (0)