Skip to content

fix(core): harden fetchImage data URLs + base64 padding test coverage - #576

Merged
ignaciosantise merged 2 commits into
developfrom
fix/fetch-image-base64-padding
Jul 14, 2026
Merged

fix(core): harden fetchImage data URLs + base64 padding test coverage#576
ignaciosantise merged 2 commits into
developfrom
fix/fetch-image-base64-padding

Conversation

@ignaciosantise

Copy link
Copy Markdown
Collaborator

Addresses the two findings from the Claude review on #575.

Issue 1 — base64 padding untested (MEDIUM, test_coverage)

Every existing fetchImage test used a byte length divisible by 3 (6 and 3 bytes), so the = / == padding branches in _arrayBufferToBase64 were never executed — despite nearly all real images having byte counts not divisible by 3. Added two cases:

  • [0x66] ("f") → Zg==
  • [0x66, 0x6f] ("fo") → Zm8=

Issue 2 — content-type params leaked into data URL (LOW, correctness)

fetchImage embedded the raw content-type header, so image/svg+xml; charset=utf-8 produced a malformed data:image/svg+xml; charset=utf-8;base64,... that strict parsers may reject. Now strips at the first ; before building the data URL, with a regression test.

Testing

  • FetchUtil.test.ts: 21 passing (3 new)
  • eslint clean on changed files
  • changeset added (patch, all 9 published packages)

🤖 Generated with Claude Code

Embed only the bare media type in the data URL so responses like
`image/svg+xml; charset=utf-8` don't produce a malformed
`data:image/svg+xml; charset=utf-8;base64,...` that strict parsers reject.

Also add test coverage for the base64 one-/two-byte padding branches
(previously every fetchImage test used a byte length divisible by 3, so
the `=`/`==` padding was never exercised).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 13, 2026 19:52
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e0f6380

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@claude

claude Bot commented Jul 13, 2026

Copy link
Copy Markdown

Claude finished @ignaciosantise's task in 2m 23s —— View job


Code Review

  • Gather context
  • Read changed files
  • Review code
  • Post findings

🔄 Incremental Review: First review of this PR.

Found 2 issue(s)

Issue 1: Misleading test description for double-char (==) padding case

ID: fetchutil-test-desc-padding-a3c1
File: packages/core/src/tests/utils/FetchUtil.test.ts:145
Severity: LOW
Category: code_quality

Context:

  • Pattern: Test name says "should produce correct single-char padding (==) for a one-byte remainder" but == is two characters (double padding), not single.
  • Risk: Future readers mapping test names to RFC 4648 padding rules will be confused — single-char padding (=) and double-char padding (==) are meaningfully distinct concepts.
  • Impact: Misleading documentation; no runtime impact.
  • Trigger: Anyone reading the test suite to understand padding behaviour.

Recommendation:

// Line 145 — change "single-char" to "double-char":
it('should produce correct double-char padding (==) for a one-byte remainder', ...)

Issue 2: Changeset bumps 8 unrelated packages

ID: changeset-overbump-unrelated-pkgs-b8f2
File: .changeset/fix-fetch-image-base64-padding.md:1
Severity: LOW
Category: maintainability

Context:

  • Pattern: The changeset bumps all 9 published packages, but the only code change is in packages/core/src/utils/FetchUtil.ts (@reown/appkit-core-react-native). Packages bitcoin, coinbase, common, ethers, solana, ui, wagmi, and the root appkit-react-native have no source changes.
  • Risk: Every dependent project consuming those 8 packages will see a patch bump with no actual change — adds noise to consumers' changelogs and can mask real version signals.
  • Impact: Unnecessary version churn across 8 packages.
  • Trigger: Any project that pins patch versions or audits changelogs.

Recommendation: Remove the 8 unrelated packages from the changeset, keeping only @reown/appkit-core-react-native: patch — unless project policy intentionally synchronises all package versions.

Breaking changes: None detected — fetchImage signature is unchanged; the new output is the correct RFC 2397 form compared to the previously malformed data URL.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens FetchUtil.fetchImage data URL generation in @reown/appkit-core-react-native by normalizing content-type headers (removing semicolon-delimited parameters) and extends unit tests to cover base64 padding branches that weren’t previously exercised.

Changes:

  • Strip content-type parameters (e.g., ; charset=utf-8) before building data:<type>;base64,... URLs in fetchImage.
  • Add unit tests to cover _arrayBufferToBase64 padding for 1-byte (==) and 2-byte (=) remainders, plus a regression test for content-type parameter stripping.
  • Add a changeset to publish patch releases across the affected packages.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/utils/FetchUtil.ts Sanitizes content-type before embedding it in a data URL returned by fetchImage.
packages/core/src/tests/utils/FetchUtil.test.ts Adds test coverage for base64 padding and content-type parameter stripping behavior.
.changeset/fix-fetch-image-base64-padding.md Declares patch bumps and documents the behavior change and new test coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/utils/FetchUtil.ts Outdated
Comment thread packages/core/src/__tests__/utils/FetchUtil.test.ts Outdated
Comment thread packages/core/src/__tests__/utils/FetchUtil.test.ts
Comment thread packages/core/src/__tests__/utils/FetchUtil.test.ts Outdated
Comment thread .changeset/fix-fetch-image-base64-padding.md Outdated
- Correct padding test name ("double-char" for the one-byte remainder `==` case)
- Rewrite content-type comment so the example data URL is accurate
- Drop the changeset

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ignaciosantise
ignaciosantise merged commit 8e991af into develop Jul 14, 2026
9 checks passed
@ignaciosantise
ignaciosantise deleted the fix/fetch-image-base64-padding branch July 14, 2026 13:42
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants