Skip to content

fix(llm): accept uppercase data URL schemes in media validation - #47648

Closed
HoneyTyagii wants to merge 1 commit into
anomalyco:devfrom
HoneyTyagii:fix-47538
Closed

HoneyTyagii wants to merge 1 commit into
anomalyco:devfrom
HoneyTyagii:fix-47538

Conversation

@HoneyTyagii

Copy link
Copy Markdown

Issue for this PR

Closes #47538

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

validateMedia detected existing data URLs with a case-sensitive startsWith("data:"), so an uppercase DATA: 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 feeds DATA: and Data: URLs and asserts the single correct data:image/png;base64,AAECAw== URL
  • bun 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 other validateMedia callers)
  • bun run typecheck — clean

Screenshots / recordings

Not applicable. No rendered UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
Copilot AI lite review requested due to automatic review settings September 6, 2026 16:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 validateMedia case-insensitive for the data: scheme.
  • Add a regression test to ensure uppercase/mixed-case DATA: inputs normalize to a single canonical lowercase data: 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 by dataUrlPattern.exec() does two regex passes and also changes behavior for malformed data: inputs: strings that start with data: 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-insensitive data: prefix check and a single exec() 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.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V2 media normalization double-prefixes uppercase DATA: URLs

2 participants