Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/uu/dirname/src/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ fn dirname_string_manipulation(path: &OsStr) -> &[u8] {
}

// Step 2: Check if it ends with `/.` and strip the `/+.` pattern
if bytes.ends_with(b".") && bytes.len() >= 2 && is_sep(bytes[bytes.len() - 2]) {
if bytes.ends_with(b".") && bytes.get(bytes.len() - 2).is_some_and(|&b| is_sep(b)) {
let dot_pos = bytes.len() - 1;
// Find where the slashes before the dot start
let mut slash_start = dot_pos - 1;
while slash_start > 0 && is_sep(bytes[slash_start - 1]) {
while bytes.get(slash_start - 1).is_some_and(|&b| is_sep(b)) {
slash_start -= 1;
}
// Return the stripped result
Expand All @@ -127,7 +127,7 @@ fn dirname_string_manipulation(path: &OsStr) -> &[u8] {
let mut result = &bytes[..last_slash_pos];

// Strip trailing slashes from result (but keep at least one if at the start)
while result.len() > 1 && is_sep(result[result.len() - 1]) {
while result.last().is_some_and(|&b| is_sep(b)) {
result = &result[..result.len() - 1];
}

Expand Down
Loading