Skip to content

fix(res): throw error when res.redirect(undefined) is called - #6942

Closed
BOXER78 wants to merge 3 commits into
expressjs:masterfrom
BOXER78:fix-redirect-undefined-behavior
Closed

fix(res): throw error when res.redirect(undefined) is called#6942
BOXER78 wants to merge 3 commits into
expressjs:masterfrom
BOXER78:fix-redirect-undefined-behavior

Conversation

@BOXER78

@BOXER78BOXER78 commented Dec 3, 2025

Copy link
Copy Markdown

Calling res.redirect(undefined) currently sends a 302 response with Location: undefined,
resulting in an invalid redirect header.

This PR throws a TypeError when the URL argument is missing, consistent with the deprecation
warning ("Provide a url argument") and prevents malformed headers.

Improved the redirect tests to match Express behavior more accurately:

  • correct expected error message
  • unified jsonError handler
  • stronger Location header assertion
  • stack presence check

The updated test suite does not change redirect behavior, but validates it more accurately and prevents future regressions.
Fixes#6941

@bjohansebas

Copy link
Copy Markdown
Member

#6948 (review)

Sign up for freeto 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.

res.redirect(undefined) sends invalid Location: undefined header

2 participants

@BOXER78@bjohansebas