Skip to content

Commit 339b893

Browse files
xydt-lcyclaude
andcommitted
fix: normalizeMediaSource should handle uppercase FILE:// URI schemes
URI schemes are case-insensitive per RFC 3986. normalizeMediaSource only matched lowercase 'file://', so MEDIA:FILE:///tmp/generated.png was left in assistant text instead of being extracted as a local media attachment. Replaced startsWith + replace with a case-insensitive regex to handle FILE://, file://, and any mixed-case variant. Fixes #103473 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent a97633a commit 339b893

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

src/media/parse.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ describe("splitMediaFromOutput", () => {
6666
String.raw`MEDIA:/path/to/image.png\"}],\"details\":{\"provider\":\"openai\"}`,
6767
],
6868
["/tmp/render,final.png", "MEDIA:/tmp/render,final.png"],
69+
["/tmp/generated.png", "MEDIA:FILE:///tmp/generated.png"],
70+
["/tmp/generated.png", "MEDIA:file:///tmp/generated.png"],
6971
] as const)("accepts supported media path variant: %s", (expectedPath, input) => {
7072
expectAcceptedMediaPathCase(expectedPath, input);
7173
});

src/media/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type SplitMediaFromOutputOptions = {
3535

3636
/** Converts file URLs into plain local paths before downstream media validation. */
3737
export function normalizeMediaSource(src: string): string {
38-
return src.startsWith("file://") ? src.replace("file://", "") : src;
38+
return src.replace(/^file:\/\//i, "");
3939
}
4040

4141
const TRAILING_SERIALIZED_JSON_AFTER_EXT_RE = /^(.*\.\w{1,10})\\?"(?=[\]},:]|$).*/s;

0 commit comments

Comments
 (0)