Skip to content

Command built from semantic types keeps padded name/description/category, so GetCommandsByCategory misses it until a save/reload #146

Description

@matt-edmondson

What's wrong

Command has two constructors, and they normalize differently.

CommandRegistry.GetCommandsByCategory (Services/CommandRegistry.cs ~L60-62) trims its input and compares with OrdinalIgnoreCase, so a stored category with padding never matches.

Reproduction (verified)

var cmd = new Command(
    CommandId.Create("edit.copy"),
    CommandName.Create(" Copy "),
    CommandDescription.Create("   "),
    CommandCategory.Create("Editing "));
// Stored: Name=" Copy ", Description="   ", Category="Editing "
registry.RegisterCommand(cmd);
registry.GetCommandsByCategory("Editing");   // 0 results
registry.GetCommandsByCategory("Editing ");  // 0 results (the input is trimmed)

After SaveAsync() and a reload, the command is rebuilt through the string constructor and trimmed, and it then appears under "Editing". The same command behaves differently before and after a round-trip.

Suggested fix / acceptance criteria

  • Have the semantic constructor apply the same normalization as the string constructor: trim the name, description and category, and turn a blank description or category into null. Ideally both constructors share one helper.
  • Add tests alongside CommandIdWhitespaceTests: padded name and category are trimmed, a whitespace-only description or category becomes null, and GetCommandsByCategory("Editing") finds the command without a save and reload.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions