Skip to content

πŸ’« Toolkit to help you get started with SDD or any other process!

fix(agents): parse frontmatter on the --- delimiter line, not any --- substring (#3590)

Andrew Chen7873c447bd5e
diff --git a/src/specify_cli/agents.py b/src/specify_cli/agents.py
index 9c9a17e2b..36a3846df 100644
--- a/src/specify_cli/agents.py
+++ b/src/specify_cli/agents.py
@@ -114,13 +114,24 @@ class CommandRegistrar:
if not content.startswith("---"):
return {}, content
- # Find second ---
- end_marker = content.find("---", 3)
- if end_marker == -1:
+ # The closing delimiter is a line that is exactly ``---`` (a YAML
+ # document separator), not any ``---`` substring. Scanning with
+ # ``content.find("---", 3)`` stops at the first ``---`` *anywhere* β€”
+ # including one embedded in a frontmatter value (e.g. a description like
+ # "Separate sections with ---") or inside an indented literal block β€”
+ # which truncates the frontmatter and spills the remainder into the
+ # body. Match on line boundaries instead, mirroring the line-anchored
+ # scan in ``VibeIntegration._inject_frontmatter_flag``.
+ lines = content.splitlines(keepends=True)
+ end_line = next(
+ (i for i in range(1, len(lines)) if lines[i].rstrip() == "---"),
+ None,
+ )
+ if end_line is None:
return {}, content
- frontmatter_str = content[3:end_marker].strip()
- body = content[end_marker + 3 :].strip()
+ frontmatter_str = "".join(lines[1:end_line]).strip()
+ body = "".join(lines[end_line + 1 :]).strip()
try:
frontmatter = yaml.safe_load(frontmatter_str) or {}
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index a7c6c7166..6190e13ef 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -2418,6 +2418,21 @@ $ARGUMENTS
assert frontmatter == {}
assert "Command body" in body
+ def test_parse_frontmatter_dash_in_value(self):
+ """A ``---`` inside a frontmatter value must not close the block early."""
+ content = """---
+description: Separate sections with --- markers
+argument-hint: "[name]"
+---
+Real body starts here.
+"""
+ registrar = CommandRegistrar()
+ frontmatter, body = registrar.parse_frontmatter(content)
+
+ assert frontmatter["description"] == "Separate sections with --- markers"
+ assert frontmatter["argument-hint"] == "[name]"
+ assert body == "Real body starts here."
+
def test_render_frontmatter(self):
"""Test rendering frontmatter to YAML."""
frontmatter = {