Skip to content

Commit e1fd805

Browse files
authored
Quote generated PRD titles (#14)
1 parent 345b8df commit e1fd805

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/prd.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function today() {
3939
return new Date().toISOString().slice(0, 10);
4040
}
4141

42+
function yamlString(value) {
43+
return JSON.stringify(String(value ?? ""));
44+
}
45+
4246
function gitEmail(root) {
4347
try {
4448
return execSync("git config user.email", { cwd: root, stdio: ["ignore", "pipe", "ignore"] })
@@ -110,7 +114,7 @@ export function renderPrd({ id, title, idea, author }) {
110114
return `---
111115
openprd: "${OPENPRD.version}"
112116
id: "${id}"
113-
title: ${title}
117+
title: ${yamlString(title)}
114118
status: Draft
115119
authors:
116120
- ${author}

test/prd.test.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { renderPrd } from "../src/prd.mjs";
5+
6+
test("renderPrd quotes titles so YAML metacharacters stay valid", () => {
7+
const body = renderPrd({
8+
id: "0001",
9+
title: 'Ship CLI: handle "quoted" flags',
10+
idea: 'Ship CLI: handle "quoted" flags',
11+
author: "dev@example.com",
12+
});
13+
14+
assert.match(body, /^title: "Ship CLI: handle \\"quoted\\" flags"$/m);
15+
});

0 commit comments

Comments
 (0)