Skip to content

Reject phrase strings and keys with spaces or commas when parsing a chord [patch] - #161

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/chord-rejects-phrase-134
Sep 30, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/chord-rejects-phrase-134

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #134

Problem

KeyStringTokenizer.SplitChord treated a , after a key as an ordinary character, and Note accepted any non-blank string. So Chord.Parse("Ctrl+K, Ctrl+C") and KeybindingService.ParseChord returned a single chord with a made-up key, "K, CTRL", that no key press can produce. The chord's ToString() then parsed back as a two-chord phrase.

Change

Tests

New ChordRejectsPhraseTests:

  • These throw for both Chord.Parse and service.ParseChord, and fail on main:
    • "Ctrl+K, Ctrl+C", "Ctrl+K,Ctrl+C", "A, B", "Ctrl+,,"
    • "Page Up", "Ctrl+Page Up", "Ctrl+,x"
  • new Note(...) throws for "K, CTRL", "PAGE UP", "A\tB" and "A+B".
  • These guard behaviour that must keep working:
    • ",", "+" and " , " are valid notes.
    • Chord.Parse("Ctrl+,") still parses.
    • Chord.Parse(chord.ToString()) round-trips for Ctrl+Alt+S, Ctrl+,, Ctrl++, Shift+F5, , and +.
    • Phrase.Parse("Ctrl+K, Ctrl+C") still splits into two chords.

The full suite passes locally: 156/156.

dotnet build Keybinding.sln fails in Keybinding.Demo with CS0618 (Profile.Chords is obsolete). That failure is the same on main and is not touched here.

🤖 Generated with Claude Code

https://claude.ai/code/session_019UNSUUrn4o84JfkEVaD3xg


Generated by Claude Code

…hord [patch]

SplitChord treated a ',' after a key as an ordinary character, and Note
accepted any non-blank string, so Chord.Parse("Ctrl+K, Ctrl+C") returned one
chord with a made-up "K, CTRL" key that could never fire, and its ToString
parsed back as a two-chord phrase. SplitChord now throws when a ',' follows a
key, and Note rejects keys containing whitespace, '+' or ',' other than the
single-character "+" and "," keys, so "Ctrl+," and "Ctrl++" still parse.

Fixes #134

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019UNSUUrn4o84JfkEVaD3xg
…der the limit

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 55d473e into main Sep 30, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/chord-rejects-phrase-134 branch September 30, 2026 04:09
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.

Chord.Parse / ParseChord accept a phrase string like "Ctrl+K, Ctrl+C" and return one chord with a made-up key "K, CTRL" instead of throwing

2 participants