Normalize the key in the Note(NoteName) constructor as the string one does - #126
Merged
Merged
Conversation
… does
The [JsonConstructor] Note(NoteName) overload canonicalized the key without
trimming or uppercasing it first, so NoteName "control" stayed "control"
rather than becoming CTRL, and "s" stayed lowercase. Chord.ToString()
uppercases for display, so the resulting chord printed as "Ctrl+S" but was
not equal to Chord.Parse("Ctrl+S"). Both constructors now go through one
NormalizeKey helper.
Fixes #121
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013qSqApi9HSiBjyHaJQYPTP
|
This was referenced Sep 27, 2026
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 #121
What was wrong
The
[JsonConstructor] Note(NoteName)overload passedkey.ToString()straight toCanonicalizeKey, which only matches uppercase text. It did not trim or uppercase first, although the string overload does both. As a result,new Note(NoteName.Create("control"))stayedcontrolrather than becomingCTRL, and"s"stayed lowercase.Chord.ToString()uppercases for display, so the broken chord still printed asCtrl+S, yet it was not equal toChord.Parse("Ctrl+S"). Bindings built this way never matched.Change
Both constructors now call one private
NormalizeKey(string)helper, which doesCanonicalizeKey(key.Trim().ToUpperInvariant()). TheNoteNameoverload still reuses the caller'sNoteNameinstance when normalizing leaves it unchanged.Tests
EveryConstructionPath_NormalizesModifierAliasesnow also builds chords fromNoteName.Create(alias)andNoteName.Create(alias.ToLowerInvariant())with a lowercaseNoteName.Create("s"). Before, it only fed that constructor pre-uppercased input, which is why the bug got through.NoteNameConstructor_MatchesStringConstructorchecksnew Note(NoteName.Create(x)) == new Note(x), including the hash code and key text, forcontrol,Control,ctrl,s,f5and" cmd ".🤖 Generated with Claude Code
https://claude.ai/code/session_013qSqApi9HSiBjyHaJQYPTP