Skip to content

Commit b6a219a

Browse files
authored
Merge pull request #8372 from drinkcat/basename-simplify
basename: Simply logic, do not trim path separators `/`
2 parents 8218f80 + 44d9cca commit b6a219a

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/uu/basename/src/basename.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use clap::{Arg, ArgAction, Command};
99
use std::collections::HashMap;
10-
use std::path::{PathBuf, is_separator};
10+
use std::path::PathBuf;
1111
use uucore::display::Quotable;
1212
use uucore::error::{UResult, UUsageError};
1313
use uucore::format_usage;
@@ -119,17 +119,8 @@ pub fn uu_app() -> Command {
119119
}
120120

121121
fn basename(fullname: &str, suffix: &str) -> String {
122-
// Remove all platform-specific path separators from the end.
123-
let path = fullname.trim_end_matches(is_separator);
124-
125-
// If the path contained *only* suffix characters (for example, if
126-
// `fullname` were "///" and `suffix` were "/"), then `path` would
127-
// be left with the empty string. In that case, we set `path` to be
128-
// the original `fullname` to avoid returning the empty path.
129-
let path = if path.is_empty() { fullname } else { path };
130-
131122
// Convert to path buffer and get last path component
132-
let pb = PathBuf::from(path);
123+
let pb = PathBuf::from(fullname);
133124

134125
pb.components().next_back().map_or_else(String::new, |c| {
135126
let name = c.as_os_str().to_str().unwrap();

0 commit comments

Comments
 (0)