From fe8060f719b1d027cf0d89b2d7c6fa7b14fde0e4 Mon Sep 17 00:00:00 2001 From: Greyson Lalonde Date: Thu, 5 Mar 2026 20:09:58 -0500 Subject: [PATCH] fix: frontmatter parser match --- lib/crewai/src/crewai/skills/parser.py | 10 ++++++---- lib/crewai/tests/skills/test_parser.py | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/crewai/src/crewai/skills/parser.py b/lib/crewai/src/crewai/skills/parser.py index 9ad08ab39..b4f257948 100644 --- a/lib/crewai/src/crewai/skills/parser.py +++ b/lib/crewai/src/crewai/skills/parser.py @@ -7,6 +7,7 @@ and provides progressive loading functions for skill data. from __future__ import annotations from pathlib import Path +import re from typing import Any import yaml @@ -16,6 +17,7 @@ from crewai.skills.validation import validate_directory_name SKILL_FILENAME: str = "SKILL.md" +_CLOSING_DELIMITER: re.Pattern[str] = re.compile(r"\n---[ \t]*(?:\n|$)") class SkillParseError(ValueError): @@ -38,13 +40,13 @@ def parse_frontmatter(content: str) -> tuple[dict[str, Any], str]: msg = "SKILL.md must start with '---' frontmatter delimiter" raise SkillParseError(msg) - end_idx = content.find("---", 3) - if end_idx == -1: + match = _CLOSING_DELIMITER.search(content, pos=3) + if match is None: msg = "SKILL.md missing closing '---' frontmatter delimiter" raise SkillParseError(msg) - yaml_content = content[3:end_idx].strip() - body = content[end_idx + 3 :].strip() + yaml_content = content[3 : match.start()].strip() + body = content[match.end() :].strip() try: frontmatter = yaml.safe_load(yaml_content) diff --git a/lib/crewai/tests/skills/test_parser.py b/lib/crewai/tests/skills/test_parser.py index 394e3d624..72d20cd11 100644 --- a/lib/crewai/tests/skills/test_parser.py +++ b/lib/crewai/tests/skills/test_parser.py @@ -48,6 +48,12 @@ class TestParseFrontmatter: fm, body = parse_frontmatter(content) assert "---" in body + def test_inline_triple_dash_in_yaml_value(self) -> None: + content = '---\nname: test\ndescription: "Use---carefully"\n---\n\nBody.' + fm, body = parse_frontmatter(content) + assert fm["description"] == "Use---carefully" + assert body == "Body." + def test_unicode_content(self) -> None: content = "---\nname: test\ndescription: Beschreibung\n---\n\nUnicode: \u00e4\u00f6\u00fc\u00df" fm, body = parse_frontmatter(content)