Skip to content

Commit b048033

Browse files
mengshengwusylvestre
authored andcommitted
ls: fix error sub dir output when hyperlink options combines with recursive
1 parent a18c132 commit b048033

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,6 +4594,36 @@ 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+
at.mkdir("example");
4602+
at.mkdir("example/a");
4603+
4604+
let result = scene
4605+
.ucmd()
4606+
.arg("--hyperlink")
4607+
.arg("--recursive")
4608+
.arg("example")
4609+
.succeeds();
4610+
4611+
let mut lines = result.stdout_str().lines();
4612+
assert!(&lines
4613+
.next()
4614+
.unwrap()
4615+
.ends_with("/example\u{7}example\u{1b}]8;;\u{7}:"));
4616+
assert!(&lines
4617+
.next()
4618+
.unwrap()
4619+
.ends_with("/example/a\u{7}a\u{1b}]8;;\u{7}"));
4620+
assert!(&lines.next().unwrap().is_empty());
4621+
assert!(&lines
4622+
.next()
4623+
.unwrap()
4624+
.ends_with("/example/a\u{7}example/a\u{1b}]8;;\u{7}:"));
4625+
}
4626+
45974627
#[test]
45984628
fn test_ls_color_do_not_reset() {
45994629
let scene: TestScenario = TestScenario::new(util_name!());

0 commit comments

Comments
 (0)