Format: a fenced block the parser reads as a step is formatted as frontmatter #284

Closed
opened 2026-11-26 19:26:58 +01:00 by abiwab · 0 comments
Owner

Found by the fuzz (format-preserves-meaning … at $.sections[].steps[], seed 3293311318, index 8841 on dev/1.6), present on main and dev/1.6.

The formatter's splitFrontmatter takes any block fenced by --- lines as frontmatter, while the parser's Frontmatter rule accepts key: value lines only: a block holding anything else is read as a step, with its comments and elements. The formatter then applies rule 10 (trailing blanks) to that "frontmatter", including inside a block comment the parser keeps verbatim, and skips rules 1-8 on its elements:

---
/* This 
is a block comment */
---

## Section

title: Com

The comment's value goes from "This \nis a block comment" to "This\nis a block comment" after gram format.

Fix: keep the textual split only when the parser finds no span (element, comment, action, title) inside the fenced block; otherwise the whole file is body.

Found by the fuzz (`format-preserves-meaning … at $.sections[].steps[]`, seed 3293311318, index 8841 on `dev/1.6`), present on `main` and `dev/1.6`. The formatter's `splitFrontmatter` takes any block fenced by `---` lines as frontmatter, while the parser's `Frontmatter` rule accepts `key: value` lines only: a block holding anything else is read as a step, with its comments and elements. The formatter then applies rule 10 (trailing blanks) to that "frontmatter", including inside a block comment the parser keeps verbatim, and skips rules 1-8 on its elements: ``` --- /* This is a block comment */ --- ## Section title: Com ``` The comment's value goes from `"This \nis a block comment"` to `"This\nis a block comment"` after `gram format`. Fix: keep the textual split only when the parser finds no span (element, comment, action, title) inside the fenced block; otherwise the whole file is body.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gram-lang/gram#284
No description provided.