Repository navigation
fix(llm): accept uppercase data URL schemes in media validation - #47648
HoneyTyagii wants to merge 1 commit into
Conversation
The data URL check in validateMedia used a case-sensitive startsWith, so an uppercase DATA: scheme fell through to the raw base64 path and the constructed data URL doubled the prefix. Parse the scheme with a case-insensitive pattern per RFC 3986 3.1 so existing data URLs are recognized regardless of casing. Closes anomalyco#47538
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, covered by a regression test, and addresses the reported double-prefixing behavior without broad behavioral risk.
Pull request overview
This PR fixes V2 media normalization by making validateMedia recognize existing data: URLs regardless of scheme casing (e.g., DATA: / Data:), preventing double-prefixing when rebuilding data URLs for provider payloads.
Changes:
- Make data-URL detection/parsing in
validateMediacase-insensitive for thedata:scheme. - Add a regression test to ensure uppercase/mixed-case
DATA:inputs normalize to a single canonical lowercasedata:URL.
File summaries
| File | Description |
|---|---|
| packages/llm/src/protocols/shared.ts | Updates media validation to treat uppercase/mixed-case data: schemes as data URLs and normalize them without double prefixing. |
| packages/llm/test/provider/openai-chat.test.ts | Adds regression coverage for uppercase/mixed-case data URL inputs in the OpenAI Chat request preparation path. |
Review details
Suppressed comments (1)
packages/llm/src/protocols/shared.ts:194
dataUrlPattern.test()followed bydataUrlPattern.exec()does two regex passes and also changes behavior for malformeddata:inputs: strings that start withdata:but don’t match the pattern will now fall through to the raw-base64 branch and return the generic “media must contain valid base64” message instead of the more specific data-URL error. Consider switching to a case-insensitivedata:prefix check and a singleexec()so malformed data URLs still get the intended error and you avoid duplicate work.
} else if (dataUrlPattern.test(part.data)) {
const match = dataUrlPattern.exec(part.data)
if (!match) return yield* invalidRequest(`${route} media data URL must contain valid base64`)
if (match[1]!.toLowerCase() !== mime)
return yield* invalidRequest(`${route} media type ${part.mediaType} does not match data URL type ${match[1]}`)
base64 = match[2]!
} else {
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #47538
Type of change
What does this PR do?
validateMediadetected existing data URLs with a case-sensitivestartsWith("data:"), so an uppercaseDATA:scheme was treated as raw base64 and the rebuilt data URL got a second prefix (data:image/png;base64,DATA:image/png;base64,...). The detection and parse pattern are now case-insensitive for the scheme, matching RFC 3986 section 3.1. The emitted data URL is unchanged for all valid inputs.How did you verify your code works?
From
packages/llm:bun test --timeout 30000 test/provider/openai-chat.test.ts— 28 pass, including a new regression test that feedsDATA:andData:URLs and asserts the single correctdata:image/png;base64,AAECAw==URLbun test --timeout 30000 test/provider/anthropic-messages.test.ts test/provider/gemini.test.ts test/provider/openai-responses.test.ts test/provider/bedrock-converse.test.ts— 129 pass (all othervalidateMediacallers)bun run typecheck— cleanScreenshots / recordings
Not applicable. No rendered UI changes.
Checklist