Skip to content

[patch] Accept only one declared SectionType name in a section header - #411

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/318-strict-section-header
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/318-strict-section-header

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #318

What changed

Section.TryParse read the [Type] header with Enum.TryParse<SectionType>. That call also accepts input that Section.ToString never writes:

  • an integer: [42] gave an undefined SectionType, and [-1] did the same
  • a comma list: [Verse, Chorus] OR'd the values together into Chorus
  • a padded name: [ Verse ]

The header now has to be the exact, letters-only name of one declared member, checked with Enum.IsDefined. Matching stays case-sensitive as before. Arrangement.Parse goes through the same path, so it picks up the fix too.

Tests

  • TryParseRejectsHeaderThatIsNotOneSectionTypeName: rejects [Verse, Chorus], [42], [-1], [ Verse ] and [verse]. Before the fix, the first four failed (the lowercase case was already rejected).
  • TryParseAcceptsEverySectionTypeName: every SectionType member still round-trips through ToString/Parse.
  • Full Semantics.Test suite on net10.0: 1486 passed, 8 skipped, 0 failed. Semantics.Music builds for every target framework, netstandard2.0 included.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A5MkmzQ4qxxRmHStdQ8oJA


Generated by Claude Code

Section.TryParse read the header with Enum.TryParse, which also takes integers
("[42]" became an undefined SectionType), comma-separated lists ("[Verse, Chorus]"
OR'd into Chorus) and padded names ("[ Verse ]"). None of those are written by
ToString, so the header now has to be the exact, letters-only name of one
declared member. Matching stays case-sensitive.

Fixes #318

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

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

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.

Section.Parse accepts numbers and comma lists as section types ([Verse, Chorus] parses as Chorus, [42] as undefined 42)

2 participants