Skip to content

fix(fetch): handle BufferSource bodies in Response#5217

Open
iammdzaidalam wants to merge 1 commit intoboa-dev:mainfrom
iammdzaidalam:fix/fetch-response-bodyinit
Open

fix(fetch): handle BufferSource bodies in Response#5217
iammdzaidalam wants to merge 1 commit intoboa-dev:mainfrom
iammdzaidalam:fix/fetch-response-bodyinit

Conversation

@iammdzaidalam
Copy link
Copy Markdown
Contributor

Closes #5216

Adds BufferSource handling to the Response() constructor body extraction path.

Currently, inputs like Uint8Array or DataView fall through to stringification,
so binary bodies end up as strings (e.g. "[object Uint8Array]") instead of raw bytes.

This change:

  • handles ArrayBuffer, typed arrays, and DataView
  • slices typed array / DataView inputs using byteOffset / byteLength
  • uses usize::try_from(...) for offsets/lengths to avoid truncation on 32-bit targets
  • preserves the existing string fallback for non-binary inputs
  • leaves other BodyInit types (e.g. Blob, FormData) for follow-up

Testing

Added tests in core/runtime/src/fetch/tests/response.rs covering:

  • ArrayBuffer
  • Uint8Array
  • subarray/view slicing
  • DataView with non-zero offset/length
  • string fallback behavior
  • content-type behavior (binary vs string)

Notes

  • binary bodies do not inject a default Content-Type
  • string bodies still default to text/plain;charset=UTF-8

@iammdzaidalam iammdzaidalam requested a review from a team as a code owner March 21, 2026 21:30
@github-actions github-actions bot added C-Tests Issues and PRs related to the tests. C-Runtime Issues and PRs related to Boa's runtime features Waiting On Review Waiting on reviews from the maintainers labels Mar 21, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 21, 2026
@github-actions
Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,539 50,545 +6
Ignored 1,426 1,426 0
Failed 998 992 -6
Panics 2 2 0
Conformance 95.42% 95.43% +0.01%
Fixed tests (6):
test/intl402/DateTimeFormat/test-option-date-time-components.js (previously Failed)
test/intl402/DateTimeFormat/constructor-options-order.js (previously Failed)
test/intl402/DateTimeFormat/constructor-options-throwing-getters.js (previously Failed)
test/intl402/DateTimeFormat/constructor-options-style-conflict.js (previously Failed)
test/intl402/DateTimeFormat/constructor-options-order-timedate-style.js (previously Failed)
test/intl402/DateTimeFormat/constructor-options-invalid-explicit-components.js (previously Failed)

Tested main commit: 58a24587890677d94618259dfaa5f257ab5ef9c9
Tested PR commit: 8190a7b88ad8f877ccf14a77c2b99b28c83cf433
Compare commits: 58a2458...8190a7b

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.83%. Comparing base (6ddc2b4) to head (8190a7b).
⚠️ Report is 929 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/fetch/response.rs 92.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5217       +/-   ##
===========================================
+ Coverage   47.24%   59.83%   +12.59%     
===========================================
  Files         476      582      +106     
  Lines       46892    63485    +16593     
===========================================
+ Hits        22154    37988    +15834     
- Misses      24738    25497      +759     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iammdzaidalam
Copy link
Copy Markdown
Contributor Author

Hey @jedel1043, any updates here when you get a moment?

@iammdzaidalam
Copy link
Copy Markdown
Contributor Author

hey @jedel1043 @nekevss ,any updates when u get a moment?

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

Labels

C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(fetch): support BufferSource bodies in Response()

1 participant