Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/prd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function today() {
return new Date().toISOString().slice(0, 10);
}

function yamlString(value) {
return JSON.stringify(String(value ?? ""));
}

function gitEmail(root) {
try {
return execSync("git config user.email", { cwd: root, stdio: ["ignore", "pipe", "ignore"] })
Expand Down Expand Up @@ -110,7 +114,7 @@ export function renderPrd({ id, title, idea, author }) {
return `---
openprd: "${OPENPRD.version}"
id: "${id}"
title: ${title}
title: ${yamlString(title)}
status: Draft
authors:
- ${author}
Expand Down
15 changes: 15 additions & 0 deletions test/prd.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from "node:assert/strict";
import test from "node:test";

import { renderPrd } from "../src/prd.mjs";

test("renderPrd quotes titles so YAML metacharacters stay valid", () => {
const body = renderPrd({
id: "0001",
title: 'Ship CLI: handle "quoted" flags',
idea: 'Ship CLI: handle "quoted" flags',
author: "dev@example.com",
});

assert.match(body, /^title: "Ship CLI: handle \\"quoted\\" flags"$/m);
});
Loading