Repository navigation
Refuse a section header outside the documented grammar [patch] - #497
Merged
Merged
Conversation
Section.TryParse looked for a label quote anywhere after "]", then for the
key "(" only after the label, and never checked what lay between or after
them. So "[Verse] (C major) \"Verse 1\"" parsed with its key silently
dropped, and junk anywhere in the header was accepted. Arrangement.Parse
reads its section headers through the same method.
After "]" the header now has to be exactly nothing, ` "<label>"`,
` (<key>)` or ` "<label>" (<key>)`, matching what ToString writes.
Fixes #492
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4o1SWh5jxZ3HQXYvx
|
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 #492
What changed
Section.TryParseused to find a label quote anywhere after], then look for the key(only after the label. It never checked the text in between or after. A chart that wrote[Verse] (C major) "Verse 1"therefore lost its local key without an error, and junk anywhere in the header was accepted.Arrangement.Parsereads section headers through the same method, so it had the same gap.After
]the header must now be exactly one of the following. These are the formsToStringwrites:"<label>"(<key>)"<label>" (<key>)The new
TryParseHeaderTail,TrySkipSeparatorandTryReadKeyhelpers do the reading, which keepsTryParseunder Sonar's cognitive-complexity limit (S3776).Tests
StrictParsingTestsgains:Section_RejectsAHeaderOutsideTheGrammarcovers the four inputs from the issue, plus a stray trailing or doubled space and a missing separator.Section_StillParsesALabelAndKeychecks that[Verse] "Verse 1" (C major)still comes back with its type, label and key.Verification
Semantics.Testsuite: 1954 passed, 14 skipped, 0 failed.Section.cschange reverted, all 9 rejection rows fail..sonarlint/sonar-local.props) onSemantics.Music. They report nothing new inSection.cs. The S3267 loop inTryParseSectionTypeand the S1192 inMode.cswere already there onmain.Generated by Claude Code