Skip to content

Fix res.links with empty values, res.append with an empty value, res.redirect for non-standard statuses, and quoted ";" in acceptParams - #70

Merged
abedmurrar merged 5 commits into
masterfrom
fix/bugs-response
Nov 22, 2026
Merged

abedmurrar merged 5 commits into
masterfrom
fix/bugs-response

Conversation

@abedmurrar

Copy link
Copy Markdown
Owner

Summary

Four bug-fix rows from ROADMAP.md, section "Bug fixes on the compatible line", all in src/response.ts and acceptParams in src/utils.ts:

  1. res.links with empty values (fix(res.links): skip empty-array rel values to prevent trailing comma in Link header expressjs/express#7320, fix(res.links): ignore empty object to prevent header corruption expressjs/express#7578)
  2. res.append keeps an existing empty header value (fix(res.append): preserve empty header values expressjs/express#7332)
  3. res.redirect body says undefined for non-standard status codes (fix(res.redirect): fallback to 'Redirecting' for non-standard status … expressjs/express#7407, fix: non standard status code will result in undefined expressjs/express#7045)
  4. Quoted ; in acceptParams (fix: acceptParams truncates quoted values containing a semicolon expressjs/express#7479)

Rows 2 and 3 said "repro needed first". Both reproduce on Express 5.3.0 (express-baseline) and on master before this change:

  • res.set('Warning', ''); res.append('Warning', '199 x') gave res.get('Warning') "199 x" (the empty value was dropped), and so did a number 0 set with res.setHeader.
  • res.redirect(399, '/x') answered undefined. Redirecting to /x (text) and <title>undefined</title><p>undefined. Redirecting to /x</p> (HTML). 310 does the same.

Changes

Behaviour

Call Express 5.3.0 Fork
res.links({ next: '/2', prev: [] }) Link: </2>; rel="next", Link: </2>; rel="next"
res.links({}), fresh response Link: (empty) no Link header
res.links({}) after a link trailing , header unchanged
res.set('X-A', ''); res.append('X-A', 'b') X-A: b X-A: and X-A: b (res.get gives ['', 'b'])
res.redirect(399, '/next'), text undefined. Redirecting to /next 399. Redirecting to /next
res.redirect(399, '/next'), HTML <title>undefined</title>... <title>399</title>...
normalizeType('text/plain; foo="a;q=0"; bar=baz') foo: '"a', quality 0 foo: '"a;q=0"', quality 1
  • Statuses with a standard message, non-empty res.append targets and unquoted type parameters are unchanged.
  • The acceptParams fix doesn't change any response: res.format only uses the type before the parameters. It shows through require('express/lib/utils').

Proof

All run locally on Node 24.17.0 in this worktree.

Planted revert Tests that fail
Whole res.links fix 14
res.links early return alone 9
res.append fix 7
res.redirect fix 10
Quote-aware scan in acceptParams 11
expressjs#7479's escape rule in place of ours 2
  • Middleware suites (node scripts/ecosystem-suites.js, on a private copy of the cache): every test that passes on 5.3.0 passes here. That covers cors 49, express-session 160, multer 173, express-rate-limit 252, http-proxy-middleware 325, express-basic-auth 25, express-openapi-validator 468, express-fileupload 203, express-mongo-sanitize 20 and hpp 17.

Benchmark

Not run. The benchmark workflows are paused, and bug fixes don't gate on them.

Risks / follow-ups

  • res.append with an empty value now sends an extra empty header line. That's harmless for list headers: RFC 9110 section 5.6.1 says recipients ignore empty list elements. It also follows what append promises. An app that set a header to '' meaning "unset" and then appended would see the extra line. No middleware suite does this.
  • res.links({}) no longer sends an empty Link header. Nothing should depend on an empty Link.
  • res.redirect bodies for statuses without a standard message change from undefined to the number, and Content-Length changes with them.
  • acceptParams keeps quotes in parameter values, as before; it doesn't unquote them.
  • res.links still throws for null or undefined, as before. fix(res.links): ignore empty object to prevent header corruption expressjs/express#7578 returns early for a falsy argument; that was left out, since it's a separate behaviour change.

…redirect for non-standard statuses, and quoted ";" in acceptParams

- res.links collects the link values first and leaves the Link header alone
  when there are none (an empty object, or relations given empty arrays), so
  no empty Link header and no trailing ", " (upstream PRs expressjs#7320, expressjs#7578).
- res.append keeps an existing empty header value, or a number 0 set with
  res.setHeader, instead of replacing it (upstream PR expressjs#7332).
- res.redirect names a status without a standard message by its number in
  the text and HTML bodies, as res.sendStatus does, instead of "undefined"
  (upstream PRs expressjs#7045, expressjs#7407).
- acceptParams ends a parameter at the next ";" outside a quoted string, with
  backslash quoted-pairs, so a quoted ";" or q stays in its value (upstream
  PR expressjs#7479, rewritten: its escape check fails on an escaped backslash).

Regression tests, edge-case tests, a property test against Express 5.3.0,
differential scenarios for each fix, and the ROADMAP, History and docs.
# Conflicts:
#	ROADMAP.md
#	docs/fork/differences.md
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 45022718148

Coverage remained the same at 100.0%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 76 of 76 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 9476
Covered Lines: 9476
Line Coverage: 100.0%
Coverage Strength: 31959.54 hits per line

💛 - Coveralls

@abedmurrar
abedmurrar merged commit 256e066 into master Nov 22, 2026
12 of 13 checks passed
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.

2 participants