Skip to content

Fix parent non-recursive arguments leaking into subcommands (#2785)#2809

Open
AhmedMyoussif wants to merge 2 commits into
dotnet:mainfrom
AhmedMyoussif:fix/root-arg-leak-2785
Open

Fix parent non-recursive arguments leaking into subcommands (#2785)#2809
AhmedMyoussif wants to merge 2 commits into
dotnet:mainfrom
AhmedMyoussif:fix/root-arg-leak-2785

Conversation

@AhmedMyoussif
Copy link
Copy Markdown

Description

This PR resolves issue #2785 where non-recursive positional arguments from parent commands were incorrectly inherited, validated, and displayed in subcommands.

Key Changes

  • Early Interception in ParseOperation: Introduced MoveNonRecursiveParentArgumentsToUnmatched inside ParseSubcommand(). When entering a subcommand, the parser immediately intercepts parent arguments configured with Recursive = false, purges them from the SymbolResultTree, and registers their tokens as UnmatchedTokens under the root command result. This completely prevents validation leaks and downstream crashes.
  • Help Architecture Alignment: Updated HelpBuilder.cs (GetUsageParts and GetCommandArgumentRows) to filter out parent arguments where Recursive == false when rendering usage strings and argument tables for subcommands.
  • Public API Contract: Added the Recursive property to the Argument class (defaulting to true to avoid breaking changes) and updated the alphabetical baseline file for API compatibility checks.
  • Test Coverage: Added dedicated unit tests for both parsing telemetry (ParserTests.cs) and layout rendering accuracy (HelpBuilderTests.cs).

Verification

  • Tested locally on net10.0 target.
  • All 929 test cases passing successfully.

@AhmedMyoussif
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant