From 63607367d3835706e9e81c6f7e28e103c5e92685 Mon Sep 17 00:00:00 2001 From: fixfon <12512757+fixfon@users.noreply.github.com> Date: Fri, 23 Oct 2026 12:05:33 +0300 Subject: [PATCH] chmod: accept modes like -=r, -+x and -,u+x extract_negative_modes only took an argument starting with '-' as a mode when its second character was a permission letter or a digit. Modes such as "-=r", "-+x" and "-,u+x" went on to clap, which has no such option and rejected them. Also accept '=', '+' and ',' there; no option starts with those. Closes #15665 --- src/uu/chmod/src/chmod.rs | 4 +++- tests/by-util/test_chmod.rs | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 80d96e855c7..55ee2d92520 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -79,11 +79,13 @@ fn extract_negative_modes(args: impl uucore::Args) -> (Option, Vec= 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' ) }; diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 01052cf6c2c..3d901f6b89f 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -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() {