Skip to content

Commit 1070f10

Browse files
test(media): consolidate MIME case coverage
Co-authored-by: 潘晓波0668000512 <[email protected]>
1 parent ccb6195 commit 1070f10

2 files changed

Lines changed: 3 additions & 35 deletions

File tree

src/media/store.test.ts

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ describe("media store", () => {
458458
},
459459
},
460460
{
461-
name: "prefers detected stream mime over generic zip header extension",
461+
name: "prefers detected stream mime over mixed-case generic zip header extension",
462462
run: async () => {
463463
await withTempStore(async (storeLocal10) => {
464464
const saved = await storeLocal10.saveMediaStream(
465465
Readable.from([Buffer.from("docx")]),
466-
"application/zip",
466+
"Application/Zip",
467467
"stream-inbound",
468468
1024,
469469
undefined,
@@ -687,22 +687,7 @@ describe("media store", () => {
687687
expectedExtension: ".custom",
688688
},
689689
{
690-
name: "does not preserve image header extensions for generic container buffers",
691-
bufferFactory: async () => {
692-
const zip = new JSZip();
693-
zip.file("hello.txt", "hi");
694-
return await zip.generateAsync({ type: "nodebuffer" });
695-
},
696-
contentType: "image/png",
697-
originalFilename: "fake.png",
698-
expectedContentType: "application/zip",
699-
expectedExtension: ".zip",
700-
assertSaved: async (saved: Awaited<ReturnType<typeof store.saveMediaBuffer>>) => {
701-
expect(path.basename(saved.path)).toMatch(/^fake---[a-f0-9-]{36}\.zip$/);
702-
},
703-
},
704-
{
705-
name: "does not preserve image header extensions for mixed-case header mime",
690+
name: "does not preserve mixed-case image header extensions for generic container buffers",
706691
bufferFactory: async () => {
707692
const zip = new JSZip();
708693
zip.file("hello.txt", "hi");
@@ -716,22 +701,6 @@ describe("media store", () => {
716701
expect(path.basename(saved.path)).toMatch(/^fake---[a-f0-9-]{36}\.zip$/);
717702
},
718703
},
719-
{
720-
name: "detects docx from mixed-case application/zip header via buffer sniffing",
721-
bufferFactory: async () => {
722-
const zip = new JSZip();
723-
zip.file("hello.txt", "hi");
724-
return await zip.generateAsync({ type: "nodebuffer" });
725-
},
726-
contentType: "Application/Zip",
727-
originalFilename: "report.docx",
728-
expectedContentType:
729-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
730-
expectedExtension: ".docx",
731-
assertSaved: async (saved: Awaited<ReturnType<typeof store.saveMediaBuffer>>) => {
732-
expect(path.basename(saved.path)).toMatch(/^report---[a-f0-9-]{36}\.docx$/);
733-
},
734-
},
735704
] as const)("$name", async (testCase) => {
736705
const buffer =
737706
"bufferFactory" in testCase && testCase.bufferFactory

src/media/store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from "@openclaw/media-core/file-name";
1212
import { detectMime, extensionForMime, normalizeMimeType } from "@openclaw/media-core/mime";
1313
import { hasHttpUrlPrefix } from "@openclaw/net-policy/url-protocol";
14-
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
1514
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
1615
import { fileStore } from "../infra/file-store.js";
1716
import { sanitizeUntrustedFileName } from "../infra/fs-safe-advanced.js";

0 commit comments

Comments
 (0)