Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(api): keep literal dashes inside skill frontmatter (#43602)

leilei31672b369e5c9444
diff --git a/api/services/agent/skill_package_service.py b/api/services/agent/skill_package_service.py
index c275b2a169d..54e38075702 100644
--- a/api/services/agent/skill_package_service.py
+++ b/api/services/agent/skill_package_service.py
@@ -363,13 +363,19 @@ class SkillPackageService:
@staticmethod
def _parse_frontmatter(content: str) -> dict[str, object]:
- if not content.startswith("---"):
+ # Delimiters are standalone lines. A literal "---" inside a YAML value must not end frontmatter.
+ lines = content.split("\n")
+ if not lines or lines[0].strip() != "---":
return {}
- parts = content.split("---", 2)
- if len(parts) < 3:
+ closing_index = None
+ for index, line in enumerate(lines[1:], start=1):
+ if line.strip() == "---":
+ closing_index = index
+ break
+ if closing_index is None:
return {}
try:
- loaded = yaml.safe_load(parts[1])
+ loaded = yaml.safe_load("\n".join(lines[1:closing_index]))
except yaml.YAMLError as exc:
raise SkillPackageError(
"invalid_frontmatter", "SKILL.md frontmatter is not valid YAML", status_code=400
diff --git a/api/tests/unit_tests/services/agent/test_skill_package_service.py b/api/tests/unit_tests/services/agent/test_skill_package_service.py
index 7ae9d504e85..0a3a9ed696b 100644
--- a/api/tests/unit_tests/services/agent/test_skill_package_service.py
+++ b/api/tests/unit_tests/services/agent/test_skill_package_service.py
@@ -242,6 +242,27 @@ def test_invalid_packages_rejected(members: dict[str, bytes], filename: str, cod
assert exc_info.value.status_code == 400
+ "description_line",
+ [
+ 'description: "Compare before---after reports."',
+ "description: Compare before---after reports.",
+ ],
+)
+def test_description_keeps_literal_dashes_inside_frontmatter(description_line: str) -> None:
+ skill_md = f"---\nname: toolkit\n{description_line}\n---\n# Instructions\nCompare reports.\n"
+ package = _normalize({"SKILL.md": skill_md.encode()})
+ assert package.manifest.name == "toolkit"
+ assert package.manifest.description == "Compare before---after reports."
+
+
+def test_opening_delimiter_with_trailing_text_is_not_frontmatter() -> None:
+ skill_md = b"---junk\nname: toolkit\ndescription: valid\n---\n# body\n"
+ with pytest.raises(SkillPackageError) as exc_info:
+ _normalize({"SKILL.md": skill_md})
+ assert exc_info.value.code == "missing_skill_name"
+
+
def test_non_zip_content_rejected():
with pytest.raises(SkillPackageError) as exc_info:
SkillPackageService().validate_and_normalize(content=b"not a zip", filename="skill.zip")