mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(media-use): escape control characters in the adopt skip line (#8087)
scanExistingAssets printed the project's own file and folder names to stderr as they are. A name holding escape sequences could rewrite or hide terminal lines. The line now goes through terminalText, like the rest of media-use's output.
This commit is contained in:
@@ -4,6 +4,7 @@ import { readManifest, appendRecord, nextId } from "./manifest.mjs";
|
||||
import { regenerateIndex } from "./index-gen.mjs";
|
||||
import { probe } from "./probe.mjs";
|
||||
import { matchTokens } from "./match.mjs";
|
||||
import { terminalText } from "./terminal-text.mjs";
|
||||
|
||||
const AUDIO_EXT = new Set([".mp3", ".wav", ".ogg", ".m4a", ".aac"]);
|
||||
const IMAGE_EXT = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg", ".ico"]);
|
||||
@@ -59,7 +60,7 @@ export function scanExistingAssets(projectDir) {
|
||||
if (stat.size === 0) {
|
||||
// A 0-byte asset would register clean but fail at render — skip it loudly
|
||||
// rather than adopt a broken file.
|
||||
console.error(`media-use: skipping 0-byte asset assets/${rel}`);
|
||||
console.error(terminalText(`media-use: skipping 0-byte asset assets/${rel}`));
|
||||
continue;
|
||||
}
|
||||
const meta = probe(fullPath);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { strict as assert } from "node:assert";
|
||||
import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { findExistingAsset, adoptExistingAssets } from "./adopt.mjs";
|
||||
import { findExistingAsset, adoptExistingAssets, scanExistingAssets } from "./adopt.mjs";
|
||||
|
||||
let tmp;
|
||||
function setup() {
|
||||
@@ -122,6 +122,25 @@ function runTests() {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("prints a skipped file name from the project with control characters escaped", () => {
|
||||
setup();
|
||||
const name = "bad\x1b]0;owned\x07\r\nok.mp3";
|
||||
mkdirSync(join(tmp, "assets", "dir\x1b[2J"), { recursive: true });
|
||||
writeFileSync(join(tmp, "assets", "dir\x1b[2J", name), "");
|
||||
const lines = [];
|
||||
const original = console.error;
|
||||
console.error = (line) => lines.push(String(line));
|
||||
try {
|
||||
assert.deepEqual(scanExistingAssets(tmp), []);
|
||||
} finally {
|
||||
console.error = original;
|
||||
}
|
||||
assert.deepEqual(lines, [
|
||||
"media-use: skipping 0-byte asset assets/dir\\x1b[2J/bad\\x1b]0;owned\\x07\\x0d\\x0aok.mp3",
|
||||
]);
|
||||
cleanup();
|
||||
});
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
for (const { name, fn } of tests) {
|
||||
|
||||
Reference in New Issue
Block a user