fix: resolve REG-04 — frontmatter inline array parser now respects quoted commas (#1695)

Fixes #1694

The inline array parser used .split(',') which ignored quote boundaries,
splitting "a, b" into two items. Replaced with a quote-aware splitter
that tracks single/double quote state.

Updated REG-04 test to assert correct behavior and added coverage for
single-quoted and mixed-quote inline arrays.
This commit is contained in:
Jeremy McSpadden
2026-04-04 14:50:01 -05:00
committed by GitHub
parent 839ea22d06
commit fa57a14ec7
2 changed files with 48 additions and 15 deletions

View File

@@ -8,6 +8,38 @@ const { safeReadFile, normalizeMd, output, error } = require('./core.cjs');
// ─── Parsing engine ───────────────────────────────────────────────────────────
/**
* Split a YAML inline array body on commas, respecting quoted strings.
* e.g. '"a, b", c' → ['a, b', 'c']
*/
function splitInlineArray(body) {
const items = [];
let current = '';
let inQuote = null; // null | '"' | "'"
for (let i = 0; i < body.length; i++) {
const ch = body[i];
if (inQuote) {
if (ch === inQuote) {
inQuote = null;
} else {
current += ch;
}
} else if (ch === '"' || ch === "'") {
inQuote = ch;
} else if (ch === ',') {
const trimmed = current.trim();
if (trimmed) items.push(trimmed);
current = '';
} else {
current += ch;
}
}
const trimmed = current.trim();
if (trimmed) items.push(trimmed);
return items;
}
function extractFrontmatter(content) {
const frontmatter = {};
// Find ALL frontmatter blocks at the start of the file.
@@ -53,8 +85,8 @@ function extractFrontmatter(content) {
// Push new context for potential nested content
stack.push({ obj: current.obj[key], key: null, indent });
} else if (value.startsWith('[') && value.endsWith(']')) {
// Inline array: key: [a, b, c]
current.obj[key] = value.slice(1, -1).split(',').map(s => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
// Inline array: key: [a, b, c] — quote-aware split (REG-04 fix)
current.obj[key] = splitInlineArray(value.slice(1, -1));
current.key = null;
} else {
// Simple key: value