Reject phrase strings and keys with spaces or commas when parsing a chord [patch] - #161
Merged
Merged
Conversation
…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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #134
Problem
KeyStringTokenizer.SplitChordtreated a,after a key as an ordinary character, andNoteaccepted any non-blank string. SoChord.Parse("Ctrl+K, Ctrl+C")andKeybindingService.ParseChordreturned a single chord with a made-up key,"K, CTRL", that no key press can produce. The chord'sToString()then parsed back as a two-chord phrase.Change
SplitChordthrowsArgumentExceptionwhen a,follows a key, and the message points at phrase parsing. A,where a key is expected is still the comma key, soCtrl+,("Ctrl++" and "Ctrl+," silently parse as plain "Ctrl", so the + and , keys cannot be bound #108) is unaffected.SplitPhraseis unchanged.Note(both constructors, throughNormalizeKey) rejects keys that contain whitespace,+or,. The single-character keys"+"and","stay valid. As the issue asked, I did not enforce the literal^[A-Z0-9_]+$NoteNamepattern.+inside a longer key (for examplenew Note("A+B")) is also rejected. It has the same round-trip problem as,, because the chord'sToStringwould re-split it.ArgumentExceptionhandling from One invalid chord entry in profiles.json makes KeybindingManager.InitializeAsync throw, although a syntactically corrupt file is tolerated #125 andNoteJsonConverter. It no longer loads a binding that can never fire.Tests
New
ChordRejectsPhraseTests:Chord.Parseandservice.ParseChord, and fail onmain:"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".",","+"and" , "are valid notes.Chord.Parse("Ctrl+,")still parses.Chord.Parse(chord.ToString())round-trips forCtrl+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.slnfails inKeybinding.DemowithCS0618(Profile.Chordsis obsolete). That failure is the same onmainand is not touched here.🤖 Generated with Claude Code
https://claude.ai/code/session_019UNSUUrn4o84JfkEVaD3xg
Generated by Claude Code