@@ -6,6 +6,7 @@ import type { MsgContext } from "../auto-reply/templating.js";
66import type { OpenClawConfig } from "../config/types.js" ;
77import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js" ;
88import { withEnvAsync } from "../test-utils/env.js" ;
9+ import { sanitizeMimeType } from "./apply.js" ;
910import { createSafeAudioFixtureBuffer } from "./runner.test-utils.js" ;
1011import type { MediaUnderstandingProvider } from "./types.js" ;
1112
@@ -1419,3 +1420,41 @@ describe("applyMediaUnderstanding", () => {
14191420 expect ( ctx . Body ) . toContain ( "vendor-json" ) ;
14201421 } ) ;
14211422} ) ;
1423+
1424+ describe ( "sanitizeMimeType" , ( ) => {
1425+ it ( "accepts a plain MIME type" , ( ) => {
1426+ expect ( sanitizeMimeType ( "image/png" ) ) . toBe ( "image/png" ) ;
1427+ expect ( sanitizeMimeType ( "application/vnd.api+json" ) ) . toBe ( "application/vnd.api+json" ) ;
1428+ } ) ;
1429+
1430+ it ( "strips standard parameters" , ( ) => {
1431+ expect ( sanitizeMimeType ( "text/plain; charset=utf-8" ) ) . toBe ( "text/plain" ) ;
1432+ expect ( sanitizeMimeType ( "text/csv;charset=UTF-8" ) ) . toBe ( "text/csv" ) ;
1433+ } ) ;
1434+
1435+ it ( "lowercases mixed-case input" , ( ) => {
1436+ expect ( sanitizeMimeType ( "Image/PNG" ) ) . toBe ( "image/png" ) ;
1437+ } ) ;
1438+
1439+ it ( "returns undefined for empty or missing input" , ( ) => {
1440+ expect ( sanitizeMimeType ( undefined ) ) . toBeUndefined ( ) ;
1441+ expect ( sanitizeMimeType ( "" ) ) . toBeUndefined ( ) ;
1442+ expect ( sanitizeMimeType ( " " ) ) . toBeUndefined ( ) ;
1443+ } ) ;
1444+
1445+ it ( "rejects malformed input with trailing junk instead of truncating" , ( ) => {
1446+ expect ( sanitizeMimeType ( "image/png junk" ) ) . toBeUndefined ( ) ;
1447+ expect ( sanitizeMimeType ( "image/png\nextra" ) ) . toBeUndefined ( ) ;
1448+ } ) ;
1449+
1450+ it ( "rejects path-like inputs that previously captured an allowlisted prefix" , ( ) => {
1451+ expect ( sanitizeMimeType ( "image/png/../etc/passwd" ) ) . toBeUndefined ( ) ;
1452+ expect ( sanitizeMimeType ( "image/png/evil" ) ) . toBeUndefined ( ) ;
1453+ } ) ;
1454+
1455+ it ( "rejects inputs without a type/subtype separator" , ( ) => {
1456+ expect ( sanitizeMimeType ( "imagepng" ) ) . toBeUndefined ( ) ;
1457+ expect ( sanitizeMimeType ( "/png" ) ) . toBeUndefined ( ) ;
1458+ expect ( sanitizeMimeType ( "image/" ) ) . toBeUndefined ( ) ;
1459+ } ) ;
1460+ } ) ;
0 commit comments