fix(2130): anchor extractFrontmatter regex to file start (#2133)

* test(2130): add failing tests for frontmatter body --- sequence mis-parse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(2130): anchor extractFrontmatter regex to file start, preventing body --- mis-parse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-04-11 23:47:50 -04:00
committed by GitHub
parent 553d9db56e
commit 637daa831b
2 changed files with 101 additions and 5 deletions

View File

@@ -42,11 +42,9 @@ function splitInlineArray(body) {
function extractFrontmatter(content) {
const frontmatter = {};
// Find ALL frontmatter blocks at the start of the file.
// If multiple blocks exist (corruption from CRLF mismatch), use the LAST one
// since it represents the most recent state sync.
const allBlocks = [...content.matchAll(/(?:^|\n)\s*---\r?\n([\s\S]+?)\r?\n---/g)];
const match = allBlocks.length > 0 ? allBlocks[allBlocks.length - 1] : null;
// Match frontmatter only at byte 0 — a `---` block later in the document
// body (YAML examples, horizontal rules) must never be treated as frontmatter.
const match = content.match(/^---\r?\n([\s\S]+?)\r?\n---/);
if (!match) return frontmatter;
const yaml = match[1];