Skip to content

Arrangement.Parse rejects a chart whose sections are separated by two blank lines or by a whitespace-only line #339

Description

@matt-edmondson

What's wrong

Arrangement.TryParse (Semantics.Music/Arrangement.cs:96) splits the text on exactly "\n\n". It then passes each block to Section.TryParse without trimming it. Section.TryParse requires the block's first character to be [ (Section.cs:116-118). Two layouts break this:

  • Three newlines between sections. The next block starts with "\n", so it fails the [ check.
  • A blank line holding a space or tab ("\n \n"). The split never happens, so two sections are read as one block.

Either way the whole parse fails.

Reproduced against HEAD 9c64b67, starting from a valid arrangement a with a Verse and a Chorus:

  • Arrangement.Parse(a.ToString()) round-trips. CRLF input is also fine.
  • Arrangement.Parse(a.ToString().Replace("\n\n", "\n\n\n")) throws FormatException.
  • Arrangement.Parse(a.ToString().Replace("\n\n", "\n \n")) throws FormatException.

Why it matters

Arrangements are hand-written chart files. An extra blank line between sections, or an editor leaving trailing whitespace on the separator line, makes a valid chart unparseable. The error doesn't point at the cause.

Suggested fix

Split into lines and treat any run of empty or whitespace-only lines as one section separator. Alternatively, trim leading and trailing newlines from each block and drop blocks that are empty after trimming.

Acceptance criteria

  • Both variants above parse equal to a.
  • The existing arrangement round-trip tests still pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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