Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ fn extract_negative_modes(args: impl uucore::Args) -> (Option<String>, Vec<OsStr
let Some(arg) = arg.to_str() else {
return false;
};
// A mode can also be "-=r", "-+x" or "-,u+x". No option starts with '=', '+' or ',',
// and a second '-' (a long option) is deliberately not listed.
arg.len() >= 2
&& arg.starts_with('-')
&& matches!(
arg.chars().nth(1).unwrap(),
'r' | 'w' | 'x' | 'X' | 's' | 't' | 'u' | 'g' | 'o' | '0'..='7'
'r' | 'w' | 'x' | 'X' | 's' | 't' | 'u' | 'g' | 'o' | '=' | '+' | ',' | '0'..='7'
)
};

Expand Down
25 changes: 25 additions & 0 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,31 @@ fn test_chmod_many_options() {
run_tests(tests);
}

#[test]
fn test_chmod_option_like_mode_starting_with_operator() {
let tests = vec![
TestCase {
args: vec!["-=r", TEST_FILE],
before: 0o100_644,
after: 0o100_444,
umask: Some(0o022),
},
TestCase {
args: vec!["-+x", TEST_FILE],
before: 0o100_644,
after: 0o100_755,
umask: Some(0o022),
},
TestCase {
args: vec!["-,u+x", TEST_FILE],
before: 0o100_644,
after: 0o100_744,
umask: Some(0o022),
},
];
run_tests(tests);
}

#[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_reference_file() {
Expand Down
Loading