fix: accept crlf command frontmatter

This commit is contained in:
Affaan Mustafa 2026-04-30 03:33:04 -04:00 committed by Affaan Mustafa
parent 01d3743a8c
commit 70cc2bb247

View File

@ -29,20 +29,17 @@ function getCommandFiles() {
} }
function parseFrontmatter(content) { function parseFrontmatter(content) {
if (!content.startsWith('---\n')) { const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
return null; return match ? match[1] : null;
}
const endIndex = content.indexOf('\n---', 4);
if (endIndex === -1) {
return null;
}
return content.slice(4, endIndex);
} }
console.log('\n=== Testing command frontmatter metadata ===\n'); console.log('\n=== Testing command frontmatter metadata ===\n');
test('frontmatter parser accepts LF and CRLF line endings', () => {
assert.strictEqual(parseFrontmatter('---\ndescription: ok\n---\n# Title'), 'description: ok');
assert.strictEqual(parseFrontmatter('---\r\ndescription: ok\r\n---\r\n# Title'), 'description: ok');
});
for (const fileName of getCommandFiles()) { for (const fileName of getCommandFiles()) {
test(`${fileName} declares command metadata frontmatter`, () => { test(`${fileName} declares command metadata frontmatter`, () => {
const content = fs.readFileSync(path.join(commandsDir, fileName), 'utf8'); const content = fs.readFileSync(path.join(commandsDir, fileName), 'utf8');