fix: quote YAML-special and numeric frontmatter values
formatValue now detects YAML-special tokens (true/false/null/yes/no/on/off/y/n/~) and numeric-looking strings, quoting them via JSON.stringify so YAML parsers cannot misread them as booleans or numbers. ISO date strings (YYYY-MM-DD) are exempt and remain bare for readability. Adds four covering tests. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -51,4 +51,14 @@ describe("serializeFrontmatter", () => {
|
||||
test("empty value becomes quoted empty string", () => {
|
||||
expect(serializeFrontmatter([{ key: "tags", value: "" }])).toBe(`---\ntags: ""\n---\n`);
|
||||
});
|
||||
test("YAML-special boolean strings are quoted", () => {
|
||||
expect(serializeFrontmatter([{ key: "draft", value: "true" }])).toBe(`---\ndraft: "true"\n---\n`);
|
||||
expect(serializeFrontmatter([{ key: "published", value: "false" }])).toBe(`---\npublished: "false"\n---\n`);
|
||||
});
|
||||
test("numeric-looking strings are quoted", () => {
|
||||
expect(serializeFrontmatter([{ key: "n", value: "42" }])).toBe(`---\nn: "42"\n---\n`);
|
||||
});
|
||||
test("ISO date strings remain bare (not quoted as numeric)", () => {
|
||||
expect(serializeFrontmatter([{ key: "date", value: "2026-06-11" }])).toBe(`---\ndate: 2026-06-11\n---\n`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user