Skip to content

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

Closed

Description

@matt-edmondson

What's wrong

Section.TryParse (Semantics.Music/Section.cs ~L129) reads the header with Enum.TryParse<SectionType>(header[1..close], …). That call is too permissive for this header:

  • It accepts any integer string and returns an undefined enum value.
  • It accepts comma-separated names and ORs their values together, flags-style.
  • It trims surrounding whitespace.

SectionType is a plain enum, so the first two cases produce wrong or undefined types.

Reproduction

Section.TryParse("[Verse, Chorus]\n4/4 C", out s)  -> true, s.Type == Chorus   (Verse=1 | Chorus=3 == 3)
Section.TryParse("[42]\n4/4 C", out s)             -> true, s.Type == (SectionType)42

Arrangement.Parse goes through the same path. An undefined type then flows into IsSameStructure and Form.

Suggested fix / acceptance criteria

  • Accept only a single, defined member name. Two ways to do that:
    • require letters only, then call Enum.TryParse and Enum.IsDefined
    • look the name up in Enum.GetNames
  • Keep matching case-sensitive as it is today, since ToString emits the exact member name.
  • Tests: [Verse, Chorus], [42], [ Verse ] and [-1] are all rejected.

Activity

  1. matt-edmondson commented on Sep 28, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    Suggested next step: require a letters-only header and add an Enum.IsDefined check, keeping the match case-sensitive. Add the four rejection tests listed in the issue.


    Generated by Claude Code

  2. added a commit that references this issue on Oct 14, 2026
    b9280e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions