diff --git a/packages/cli/src/media-use/lib/index-gen.mjs b/packages/cli/src/media-use/lib/index-gen.mjs index 748c0ad77d..2e6cf0a6ad 100644 --- a/packages/cli/src/media-use/lib/index-gen.mjs +++ b/packages/cli/src/media-use/lib/index-gen.mjs @@ -1,8 +1,10 @@ import { currentRecords, indexPath, ownMediaDir, replaceFile } from "./manifest.mjs"; +import { terminalText } from "./terminal-text.mjs"; + +const LINE_BREAKS = /\s*[\r\n\v\f\u0085\u2028\u2029]+\s*/g; -// One table cell: a line break in a record would start a new line of the index, so it becomes a space. function cell(value) { - return String(value ?? "").replace(/\s*[\r\n]+\s*/g, " "); + return terminalText(String(value ?? "").replace(LINE_BREAKS, " ")); } function pad(str, len) { diff --git a/packages/core/src/figma/mediaIndex.test.ts b/packages/core/src/figma/mediaIndex.test.ts index 9daa13ddc4..a4e5689df1 100644 --- a/packages/core/src/figma/mediaIndex.test.ts +++ b/packages/core/src/figma/mediaIndex.test.ts @@ -126,17 +126,41 @@ describe("regenerateIndex", () => { }); }); -describe("generateIndexContent with line breaks in a row", () => { +describe("generateIndexContent with line breaks and control characters in a row", () => { const BROKEN_ROWS = [ { ...IMAGE_ROW, id: "image_009\r\n", description: "first line\nsecond line\r\n third" }, { ...ICON_ROW, path: ".media/images/\nicon.svg", description: "\n" }, + { + ...IMAGE_ROW, + id: "image_010", + description: "a\u2028b\u2029c\u0085d\u000be\u000cf", + }, + { + ...IMAGE_ROW, + id: "image_011\u0000", + description: "red\u001b[31m\u0007 bell\u007f\u009b\ttab", + }, ]; it("keeps each row on one line", () => { - const lines = generateIndexContent(BROKEN_ROWS).trimEnd().split("\n"); + const lines = generateIndexContent(BROKEN_ROWS) + .trimEnd() + .split(/\r\n|[\n\r\v\f\u0085\u2028\u2029]/); // Title, blank line, column heading, then one line per row. expect(lines).toHaveLength(3 + BROKEN_ROWS.length); expect(lines[3]).toContain("first line second line third"); + expect(lines[5]).toContain("a b c d e f"); + }); + + it("shows other control characters as visible escapes and keeps tabs", () => { + const content = generateIndexContent(BROKEN_ROWS); + const controls = [...content].filter((ch) => { + const code = ch.charCodeAt(0); + return (code < 0x20 && code !== 0x09 && code !== 0x0a) || (code >= 0x7f && code <= 0x9f); + }); + expect(controls).toEqual([]); + expect(content).toContain("image_011\\x00"); + expect(content).toContain("red\\x1b[31m\\x07 bell\\x7f\\x9b\ttab"); }); it("matches media-use's index-gen output byte-for-byte", () => { diff --git a/packages/core/src/figma/mediaIndex.ts b/packages/core/src/figma/mediaIndex.ts index 115a8197b4..34d46bb23c 100644 --- a/packages/core/src/figma/mediaIndex.ts +++ b/packages/core/src/figma/mediaIndex.ts @@ -9,6 +9,7 @@ import { join } from "node:path"; import { replaceFileAtomically } from "../atomicFile"; +import { terminalText } from "../terminalText"; import { readJsonlValues } from "./jsonl"; import { manifestPath, mediaDir, ownMediaDir } from "./manifest"; @@ -22,8 +23,10 @@ export function indexPath(projectDir: string): string { return join(mediaDir(projectDir), "index.md"); } +const LINE_BREAKS = /\s*[\r\n\v\f\u0085\u2028\u2029]+\s*/g; + function singleLineCell(value: unknown): string { - return String(value ?? "").replace(/\s*[\r\n]+\s*/g, " "); + return terminalText(String(value ?? "").replace(LINE_BREAKS, " ")); } function pad(str: unknown, len: number): string { diff --git a/skills-manifest.json b/skills-manifest.json index ef8f19ed63..0c54fb0277 100644 --- a/skills-manifest.json +++ b/skills-manifest.json @@ -18,7 +18,7 @@ "files": 13 }, "media-use": { - "hash": "9740d923a54e63ba", + "hash": "6dee8b534a8fe0a9", "files": 130 }, "remotion-to-hyperframes": { diff --git a/skills/media-use/scripts/lib/index-gen.mjs b/skills/media-use/scripts/lib/index-gen.mjs index 748c0ad77d..2e6cf0a6ad 100644 --- a/skills/media-use/scripts/lib/index-gen.mjs +++ b/skills/media-use/scripts/lib/index-gen.mjs @@ -1,8 +1,10 @@ import { currentRecords, indexPath, ownMediaDir, replaceFile } from "./manifest.mjs"; +import { terminalText } from "./terminal-text.mjs"; + +const LINE_BREAKS = /\s*[\r\n\v\f\u0085\u2028\u2029]+\s*/g; -// One table cell: a line break in a record would start a new line of the index, so it becomes a space. function cell(value) { - return String(value ?? "").replace(/\s*[\r\n]+\s*/g, " "); + return terminalText(String(value ?? "").replace(LINE_BREAKS, " ")); } function pad(str, len) {