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: avoid serializing body with buffer type #273

Merged
merged 1 commit into from
Aug 23, 2023
Merged

fix: avoid serializing body with buffer type #273

merged 1 commit into from
Aug 23, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 23, 2023

πŸ”— Linked issue

resolves #269

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Normally we allow serializing pure objects (with object constructor) OR classes that implement toJSON().

However Buffer type is different and implements a toJSON method which is mainly for debugging.

This PR detects buffer type without depending on global Buffer as (Node.js) workaround

Note: Worth to mention that other BodyInit compatible types such as UInt8Array do not share this issue as do not implement toJSON. We might consider detecting them explicitly if any runtime in the feature does. (-- Investigating Readable Body stream in next steps, current check currently allows it to be unserialized --)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Merging #273 (fe5157b) into main (b9ef395) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #273      +/-   ##
==========================================
+ Coverage   92.35%   92.39%   +0.04%     
==========================================
  Files           5        5              
  Lines         523      526       +3     
  Branches       97       99       +2     
==========================================
+ Hits          483      486       +3     
  Misses         40       40              
Files Changed Coverage Ξ”
src/utils.ts 95.61% <100.00%> (+0.11%) ⬆️

@pi0 pi0 marked this pull request as draft August 23, 2023 13:20
@pi0 pi0 marked this pull request as ready for review August 23, 2023 15:22
@pi0 pi0 merged commit cb05d8f into main Aug 23, 2023
6 checks passed
@pi0 pi0 deleted the fix/buff-body branch August 23, 2023 15:22
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.

Handle body types other than string and plain object
1 participant