Skip to content

Fix req.subdomains with a root dot and view engine extension case - #69

Merged
abedmurrar merged 2 commits into
masterfrom
fix/bugs-request-views
Nov 22, 2026
Merged

abedmurrar merged 2 commits into
masterfrom
fix/bugs-request-views

Conversation

@abedmurrar

Copy link
Copy Markdown
Owner

Summary

Three rows from ROADMAP.md, "Bug fixes on the compatible line":

Changes

  • src/request.ts: req.subdomains drops one trailing . from the hostname before splitting it. req.hostname is unchanged and keeps the dot.

  • src/view.ts: the View constructor looks for an engine in this order:

    1. the exact key, as before;
    2. any registered key that matches ignoring case (engineIgnoringCase). It uses for...in, so a sub-app checks its own engines first, then the ones it inherits from its parent;
    3. the require() fallback, as before.

    this.ext, the file name it looks up and app.engines are left as they were.

  • Tests:

    • regression tests for both fixes in test/regressions/request-and-routing.js;
    • a pinned test for the reason async lookup can't land on this line;
    • edge cases in test/fork-request-getters.js and test/app.engine.js;
    • 2 differential scenarios, listed in allowed.
  • Docs: ROADMAP rows, History.md, docs/fork/differences.md, docs/api/request.md and docs/api/application.md.

Behaviour

  • Host: tobi.ferrets.example.com. now gives req.subdomains ["ferrets", "tobi"]. 5.3.0 gives ["example", "ferrets", "tobi"].
    • With subdomain offset 0 it gives ["com", "example", "ferrets", "tobi"].
    • 127.0.0.1. counts as an IP, so it has no subdomains.
    • Only one dot is dropped: a.. still has an empty label.
  • app.engine('HTML', fn) now renders user.html. 5.3.0 tried require('html') and threw synchronously.
  • Async view lookup is not compatible, checked against 5.3.0:
    • On 5.3.0, a missing view reaches the render callback before app.render returns. So res.render(name, (err, html) => { if (err) throw err }) throws to the route handler, and the router turns it into a 500.
    • An async lookup can only report a missing view from an fs.stat callback. There, the same throw is uncaught and ends the process.
    • The pinned test fails when the error is delivered later. I checked this by planting process.nextTick(done, err) in app.render: the test failed, and the run also had an unhandled error.
    • The upstream PR also leaves view.path unset after new View(), makes lookup take a callback, and removes resolve.
    • On master, only renders with view cache off do file I/O on every render. Production turns view cache on.

Proof

  • npm run lint, npm run typecheck and npm run test:types are clean.
  • npm run test-ci: 141 files, 8568 passed and 5 skipped. Coverage is 100% for statements, branches, functions and lines, and "Coverage report covers all 23 source files."
  • REGRESSIONS_ALL=1 npx vitest run, master compared with this branch by test name:
  • Planted reverts, with the tests kept:
    • restoring master's src/request.ts fails 18 tests: the regression test, 15 edge cases and 2 differential scenarios;
    • restoring master's src/view.ts fails 10 tests: the regression test, 7 edge cases and 2 differential scenarios.
  • Reproduced before changing anything, on both 5.3.0 and master:
    • Host: tobi.ferrets.example.com. gives ["example", "ferrets", "tobi"];
    • app.engine('HTML') with user.html throws Cannot find module 'html'.

Benchmark

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

Risks / follow-ups

  • Engine matching:
    • An app that registered engines differing only in case, and relied on x.HTML reaching the require() fallback, now gets the registered engine. The require() fallback still uses the extension as written (require('EJS')).
    • When an engine is found in another case, it is matched again on every render. Nothing is written into app.engines.
  • Async view lookup is on the 6.x table. Proof planned there:
    • the tests from the upstream PR;
    • a test that spies on fs.*Sync;
    • the pinned test, turned the other way.

- req.subdomains drops the trailing DNS root dot of a fully qualified host
  ("tobi.ferrets.example.com." gives ["ferrets", "tobi"]). Reproduced on
  Express 5.3.0 and master first. Ported from upstream PR expressjs#7331 by
  lin-hongkuan (expressjs#7331).
- A view's extension matches a registered engine ignoring case (expressjs#4594,
  expressjs#4594): exact case first, then
  any other case, own engines before a sub-app's inherited ones, then the
  require() fallback as before. app.engines keys and file names keep their
  case. Our own fix: upstream PR expressjs#7051 by Erdinc Curebal lowercases the
  stored keys and the extension added to file names, which changes
  app.engines and which files a case-sensitive file system finds.
- Async view lookup (upstream PR expressjs#2653) moves to the 6.x table: a missing
  view reaches the render callback before app.render returns on 5.3.0, so
  `if (err) throw err` reaches the caller; an async lookup would throw from
  an fs callback and end the process. A pinned regression test guards it.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 45022132691

Coverage remained the same at 100.0%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 38 of 38 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: 9436
Covered Lines: 9436
Line Coverage: 100.0%
Coverage Strength: 32043.75 hits per line

💛 - Coveralls

@abedmurrar
abedmurrar merged commit b237c0a into master Nov 22, 2026
12 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.

ext should be case-insensitive for view engines.

2 participants