Skip to content

UnbindChord/GetChord/HasChordBinding(commandId) throw on a blank id once a profile is active, but return false/null otherwise #129

Description

@matt-edmondson

What's wrong

The active-profile overloads in Keybinding/Services/KeybindingService.cs don't guard commandId:

  • GetChord(commandId) (~line 93)
  • UnbindChord(commandId) (~line 131)
  • HasChordBinding(commandId) (~line 253)

They forward to Profile.GetChord, Profile.RemoveChord and Profile.HasChord, which throw ArgumentException on whitespace. The (profileId, commandId) overloads check string.IsNullOrWhiteSpace(commandId) and return null or false.

Reproduction

svc.UnbindChord("  ");        // no active profile  -> false
svc.SetActiveProfile("p");
svc.UnbindChord("  ");        // -> throws ArgumentException
svc.GetChord("  ");           // -> throws ArgumentException
svc.GetChord("p", "  ");      // -> null

This was reproduced with a temporary MSTest test.

Why it matters

The result for the same input depends on whether a profile happens to be active, which is hidden state. The documented contract for UnbindChord is "false if it didn't exist or no active profile", and a caller that follows it can crash. The one-argument and two-argument overloads also disagree for identical inputs.

This is separate from #123. That issue is about a Command whose id has surrounding whitespace; this one is about blank ids passed to the lookup and unbind methods.

Suggested fix

Add the same if (string.IsNullOrWhiteSpace(commandId)) return null/false; guard that the profile-id overloads use.

Acceptance: for a blank commandId, the one-argument overloads return the same result as the two-argument ones, whether or not a profile is active.

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions