Merge pull request #8374 from sylvestre/issue-8373

basename: handle a corner case with /. - Closes #8373
This commit is contained in:
Daniel Hofstetter
2025-07-23 14:47:27 +02:00
committed by GitHub
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -119,6 +119,11 @@ pub fn uu_app() -> Command {
}
fn basename(fullname: &str, suffix: &str) -> String {
// Handle special case where path ends with /.
if fullname.ends_with("/.") {
return ".".to_string();
}
// Convert to path buffer and get last path component
let pb = PathBuf::from(fullname);
+7
View File
@@ -183,6 +183,13 @@ fn test_triple_slash() {
new_ucmd!().arg("///").succeeds().stdout_is(expected);
}
#[test]
fn test_trailing_dot() {
new_ucmd!().arg("/.").succeeds().stdout_is(".\n");
new_ucmd!().arg("hello/.").succeeds().stdout_is(".\n");
new_ucmd!().arg("/foo/bar/.").succeeds().stdout_is(".\n");
}
#[test]
fn test_simple_format() {
new_ucmd!().args(&["a-a", "-a"]).succeeds().stdout_is("a\n");