Merge pull request #8374 from sylvestre/issue-8373
Some checks are pending
CICD / Build (push) Blocked by required conditions
CICD / Style/deps (push) Waiting to run
CICD / Style/cargo-deny (push) Waiting to run
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Build/SELinux (push) Blocked by required conditions
GnuTests / Run GNU tests (push) Waiting to run
Android / Test builds (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run

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
commit cf3fece177
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

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);

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");