fix: throw TypeError for invalid arguments in res.redirect()#7049
Closed
erdinccurebal wants to merge 1 commit intoexpressjs:masterfrom
Closed
fix: throw TypeError for invalid arguments in res.redirect()#7049erdinccurebal wants to merge 1 commit intoexpressjs:masterfrom
erdinccurebal wants to merge 1 commit intoexpressjs:masterfrom
Conversation
Previously, res.redirect() with non-string url (e.g. undefined, null) would only emit a deprecation warning but still send a malformed HTTP response with an invalid Location header (e.g. "Location: undefined"). This converts the deprecated behavior into thrown TypeErrors, consistent with how res.status() validates its input. This prevents sending invalid HTTP responses and gives developers clear, actionable errors. Fixes expressjs#6941
Member
|
duplicated of #6404 |
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.
Summary
res.redirect(undefined)previously sent a malformed HTTP response withLocation: undefinedheader. While a deprecation warning was emitted, the invalid response was still sent to the client.TypeErrors, consistent with howres.status()already validates its input (see response.js#L64-L72).url(must be a string) andstatus(must be a number) arguments.Before
After
Test plan
res.redirect(undefined)throws (500)res.redirect(null)throws (500)res.redirect(123)throws (500)res.redirect(301, undefined)throws (500)res.redirect('301', '/foo')throws (500)Fixes #6941