Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(body mixin): only allow Uint8Array chunks #1550

Merged
merged 2 commits into from Jul 16, 2022

Conversation

KhafraDev
Copy link
Member

I was writing a regression test for nodejs/node#43838 and discovered that the body mixin methods were still not spec-compliant. According to the stream standards, every chunk must be a Uint8Array when reading a body.

  1. body-mixin .text() (for example), calls consume body
  2. consume body calls fully reading body as promise
  3. fully reading body as promise calls ReadableStreamDefaultReader read all bytes
  4. and then read loop is called
  5. read loop chunk steps says "If chunk is not a Uint8Array object, reject promise with a TypeError and abort these steps."

Writing this out because it's very convoluted any might help someone understand this in the future.

p.s.: .formData() likely isn't correct still, but I left it untouched.

@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2022

Codecov Report

Merging #1550 (dd80fec) into main (6c9e634) will decrease coverage by 0.01%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main    #1550      +/-   ##
==========================================
- Coverage   94.91%   94.89%   -0.02%     
==========================================
  Files          50       50              
  Lines        4678     4686       +8     
==========================================
+ Hits         4440     4447       +7     
- Misses        238      239       +1     
Impacted Files Coverage Δ
lib/fetch/body.js 97.59% <75.00%> (-1.15%) ⬇️
lib/fetch/file.js 92.85% <0.00%> (+1.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c9e634...dd80fec. Read the comment docs.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@ronag ronag merged commit b6af4e6 into nodejs:main Jul 16, 2022
@KhafraDev KhafraDev deleted the new-response-readable branch July 16, 2022 15:29
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants