fix: allow query strings and fragments in image URL regex (#484) - #485
Merged
robert-j-y merged 1 commit intoApr 28, 2026
Merged
Conversation
The supportedUrls['image/*'] regex anchored the extension to the end of the string, so URLs with ?query or #fragment did not match and got downloaded + base64-inlined by the AI SDK layer. Updated both chat and completion models to accept an optional [?#].* suffix after the extension. Strict allowlist behavior (extension required, terminal) is preserved. Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
robert-j-y
deleted the
devin/1777126008-fix-issue-484-image-url-query-params
branch
April 28, 2026 19:08
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #484 — the
supportedUrls['image/*']regex anchored the extension to the end of the string with$, so any valid image URL with a query string or fragment (e.g.https://cdn.example.com/photo.png?height=200) did NOT match. WhensupportedUrlsdoesn't match, the AI SDK'sLanguageModelV3layer downloads the image and inlines it as base64 into the prompt, which bloats conversation history and inflates token usage.The fix relaxes the pattern to allow an optional
?...and/or#...suffix after the extension. Strict allowlist behavior is preserved — the extension is still required and must remain terminal in the path. The same fix is applied to bothsrc/chat/index.tsandsrc/completion/index.tsto keep them in sync. Thedata:image/...pattern is left unchanged.Before / after
Test coverage
Added
e2e/issues/issue-484-image-url-query-params.test.tswith 32 unit-style cases (no network) covering bothchatandcompletionsupportedUrls:?...#...suffixesdata:URIs — must still match?/#, uppercase extension with query.../some.png/redirect,.../photo.jpg/thumbnail) — must REMAIN rejected (guards against overly-loose relaxations)On current
main16 of these cases fail; with the fix all 32 pass.Reviewer checklist
Verified against the diff at HEAD:
src/chat/index.ts:73andsrc/completion/index.ts:57updated identically (same regex literal in both files)data:image/...pattern unchanged (/^data:image\/[a-zA-Z]+;base64,/)application/*andtext/*patterns untouchedas/ type assertions introduced (onlyas constliteral-narrowing in the new test, which is allowed).../some.png/redirectand.../photo.jpg/thumbnailconfirmed still rejected)main(16/32 fail) and passes on this branch (32/32)Checklist
pnpm stylecheckandpnpm typecheckpnpm testand all tests passChangeset
pnpm changesetto create a changeset file