fix(ts-sdk): decode base64 data URLs with media-type parameters - #247
Open
rohitsux wants to merge 1 commit into
Open
fix(ts-sdk): decode base64 data URLs with media-type parameters#247rohitsux wants to merge 1 commit into
rohitsux wants to merge 1 commit into
Conversation
toImageBytes()'s regex ^data:[^;]+;base64, requires a ;-free media type, so valid RFC 2397 data URLs with a media-type parameter (e.g. data:image/svg+xml;charset=utf-8;base64,...) or an omitted media type (data:;base64,...) don't match and fall through, handing the entire data URL to the base64 decoder. That decoder then throws InvalidCharacterError under atob (browser) or silently corrupts bytes under Buffer.from (Node). Fix matches up to the ;base64, marker ([^,]*) instead. Base64 payloads never contain a comma, so the payload is still captured correctly. No change in behavior for existing inputs. Added two regression tests covering a media type with a parameter and an omitted media type.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChangesImage data URL decoding
Merge Risk: ⚪ Minimal · up to This localized change correctly handles base64 data URLs with media-type parameters or omitted media types, with regression coverage and passing checks. No actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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.
Problem
toImageBytes()inpackages/sie_ts_sdk/src/images.tsdetects base64 data URLs with the regex:This requires the media type segment to contain no
;. Per RFC 2397, though, the media type may carry parameters (e.g.;charset=utf-8) or be omitted entirely. Data URLs like:data:image/svg+xml;charset=utf-8;base64,...data:;base64,...don't match this pattern and fall through to the plain base64 branch, which hands the entire data URL string (including the
data:...;base64,prefix) to the base64 decoder. That decoder then either throwsInvalidCharacterErrorunderatob(browser) or silently produces corrupted bytes underBuffer.from(Node) — neither of which surfaces as a clear "unsupported input" error.Fix
Match up to the
;base64,marker instead of requiring a;-free segment:Base64 payloads never contain a comma, so the capture group still correctly isolates just the payload. Behavior for all previously-matching data URLs is unchanged.
Tests
Added two regression tests to
packages/sie_ts_sdk/tests/images.test.ts:image/svg+xml;charset=utf-8)data:;base64,...)Verified locally: fails-before (both new tests throw on the unpatched regex) / passes-after.
tests/images.test.ts17/17; full@superlinked/sie-sdksuite 484/484;biome checkclean;tsc --noEmit(typecheck) clean.Summary by CodeRabbit
Bug Fixes
Tests