fix: Match skill frontmatter closing fence

This commit is contained in:
Danny Avila 2026-05-26 17:53:04 -07:00
parent 6e6e5a29f4
commit 432227055c
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
2 changed files with 14 additions and 3 deletions

View file

@ -188,6 +188,16 @@ describe('parseFrontmatter', () => {
});
});
it('does not treat frontmatter scalar lines that start with --- text as closing fences', () => {
const raw = `---\nname: marker\ndescription: 'first\n---not a closing fence\nlast'\nalways-apply: false\n---\n\nbody`;
expect(parseFrontmatter(raw)).toEqual({
name: 'marker',
description: 'first ---not a closing fence last',
alwaysApply: false,
invalidBooleans: [],
});
});
it('returns empty fields when frontmatter is unterminated', () => {
const raw = `---\nname: incomplete\n`;
expect(parseFrontmatter(raw)).toEqual({

View file

@ -23,11 +23,12 @@ function extractFrontmatterBlock(raw: string): string | null {
if (!content.startsWith('---\n')) {
return null;
}
const closingIdx = content.indexOf('\n---', 4);
if (closingIdx === -1) {
const body = content.slice(4);
const closingFence = /(?:^|\n)---[ \t]*(?:\n|$)/.exec(body);
if (!closingFence) {
return null;
}
return content.slice(4, closingIdx);
return body.slice(0, closingFence.index);
}
function getCaseInsensitive(frontmatter: Record<string, unknown>, key: string): unknown {