Skip to content

Commit

Permalink
ls: fix error sub dir output (#6521)
Browse files Browse the repository at this point in the history
Closes #6492
  • Loading branch information
mengshengwu authored Jul 5, 2024
1 parent a18c132 commit 1e80d3e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ impl PathData {

fn show_dir_name(path_data: &PathData, out: &mut BufWriter<Stdout>, config: &Config) {
if config.hyperlink && !config.dired {
let name = escape_name(&path_data.display_name, &config.quoting_style);
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();
} else {
Expand Down
43 changes: 43 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4594,6 +4594,49 @@ fn test_ls_hyperlink_dirs() {
.contains(&format!("{path}{separator}{dir_b}\x07{dir_b}\x1b]8;;\x07:")));
}

#[test]
fn test_ls_hyperlink_recursive_dirs() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let path = at.root_dir_resolved();
let separator = std::path::MAIN_SEPARATOR_STR;

let dir_a = "a";
let dir_b = "b";
at.mkdir(dir_a);
at.mkdir(format!("{dir_a}/{dir_b}"));

let result = scene
.ucmd()
.arg("--hyperlink")
.arg("--recursive")
.arg(dir_a)
.succeeds();

macro_rules! assert_hyperlink {
($line:expr, $expected:expr) => {
assert!(matches!($line, Some(l) if l.starts_with("\x1b]8;;file://") && l.ends_with($expected)));
};
}

let mut lines = result.stdout_str().lines();
assert_hyperlink!(
lines.next(),
&format!("{path}{separator}{dir_a}\x07{dir_a}\x1b]8;;\x07:")
);
assert_hyperlink!(
lines.next(),
&format!("{path}{separator}{dir_a}{separator}{dir_b}\x07{dir_b}\x1b]8;;\x07")
);
assert!(matches!(lines.next(), Some(l) if l.is_empty()));
assert_hyperlink!(
lines.next(),
&format!(
"{path}{separator}{dir_a}{separator}{dir_b}\x07{dir_a}{separator}{dir_b}\x1b]8;;\x07:"
)
);
}

#[test]
fn test_ls_color_do_not_reset() {
let scene: TestScenario = TestScenario::new(util_name!());
Expand Down

0 comments on commit 1e80d3e

Please sign in to comment.