fix: TypeError: Cannot read properties of undefined (reading 'body') …#1846
Open
Pruthvik-P wants to merge 1 commit intonode-fetch:mainfrom
Open
fix: TypeError: Cannot read properties of undefined (reading 'body') …#1846Pruthvik-P wants to merge 1 commit intonode-fetch:mainfrom
Pruthvik-P wants to merge 1 commit intonode-fetch:mainfrom
Conversation
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.
fix: guard against undefined request/options in redirect step (fixes #1845)
Purpose
Prevent a runtime crash in the redirect-follow logic when either the internal
requestinstance oroptions_object is everundefined. Without this guard, callingfetch()on certain redirect sequences (e.g. 308 → 302 with a stream body) throwsChanges
src/index.js, changed the redirect-step-9 guard to use optional chaining (request?.bodyandoptions_?.body) rather than assuming those objects always exist.dist/bundle so the distributed code includes this guard.Additional information
I did not add unit tests in this PR—but I can follow up with a mocha/jest test if you'd like. Manual repro code is in
test/manual/redirect-repro.js(feel free to move it or convert it into an automated test suite).Checklist