Skip to content

Trim the id in the Command(CommandId) constructor as the string one does - #138

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/trim-command-id-123
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/trim-command-id-123

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #123

What was wrong

Command(string id, …) trims the id, but Command(CommandId id, …) stored it as given. CommandRegistry keys its dictionary on command.Id untrimmed, while IsCommandRegistered, GetCommand and UnregisterCommand trim the id they are given before looking it up. So a command built from CommandId.Create(" file.save ") registered and showed up in listings, but could never be found, bound or unregistered.

Change

  • The CommandId constructor now trims the id in the same place the string constructor does. An id that is already trimmed is kept as the same instance, following the Note(NoteName) pattern.
  • A whitespace-only CommandId now throws ArgumentException, which the constructor's XML doc already promised.
  • As the issue recommends, CommandId's regex is still not enforced.

Tests

CommandIdWhitespaceTests has 4 tests. They check that the id is trimmed, that the command equals one built with the string constructor, that a whitespace-only id is rejected, and that a padded command can be registered, found, bound and unregistered. All 4 fail when the fix is reverted. Full suite: 106/106 pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X65VbCUfvG15D4o8afrvpk


Generated by Claude Code

…oes [patch]

CommandRegistry keys commands on Command.Id but trims the id every lookup
is given, so a Command built from a CommandId with surrounding whitespace
registered under a key no lookup could produce: it showed up in listings
but could never be found, bound or unregistered. The CommandId constructor
now trims like the string constructor, and rejects a whitespace-only id.

Fixes #123

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X65VbCUfvG15D4o8afrvpk
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 3c02fc8 into main Sep 27, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/trim-command-id-123 branch September 27, 2026 15:08
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.

A Command built from a CommandId with surrounding whitespace registers but can never be found, bound or unregistered

1 participant