Repository navigation
Fix req.subdomains with a root dot and view engine extension case - #69
Merged
Merged
Conversation
- 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.
Coverage Report for CI Build 45022132691Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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
Three rows from ROADMAP.md, "Bug fixes on the compatible line":
req.subdomainsignores a trailing root dot: fixed. Port of fix(req): ignore trailing root dot in subdomains expressjs/express#7331.extshould be case-insensitive for view engines. expressjs/express#4594, without taking fix: make view engine extension matching case-insensitive expressjs/express#7051.Changes
src/request.ts:req.subdomainsdrops one trailing.from the hostname before splitting it.req.hostnameis unchanged and keeps the dot.src/view.ts: theViewconstructor looks for an engine in this order:engineIgnoringCase). It usesfor...in, so a sub-app checks its own engines first, then the ones it inherits from its parent;require()fallback, as before.this.ext, the file name it looks up andapp.enginesare left as they were.Tests:
test/regressions/request-and-routing.js;test/fork-request-getters.jsandtest/app.engine.js;allowed.Docs: ROADMAP rows, History.md,
docs/fork/differences.md,docs/api/request.mdanddocs/api/application.md.Behaviour
Host: tobi.ferrets.example.com.now givesreq.subdomains["ferrets", "tobi"]. 5.3.0 gives["example", "ferrets", "tobi"].subdomain offset0 it gives["com", "example", "ferrets", "tobi"].127.0.0.1.counts as an IP, so it has no subdomains.a..still has an empty label.app.engine('HTML', fn)now rendersuser.html. 5.3.0 triedrequire('html')and threw synchronously.htmlrenderspage.HTML.view engineHtml, Express still looks forpage.Html, so lookups don't depend on whether the file system ignores case.app.enginesand the extension added to file names. That changesapp.engines, and on Linux it stops findingpage.Htmlfiles that 5.3.0 finds, which is the compatibility concern raised inextshould be case-insensitive for view engines. expressjs/express#4594.app.renderreturns. Sores.render(name, (err, html) => { if (err) throw err })throws to the route handler, and the router turns it into a 500.fs.statcallback. There, the same throw is uncaught and ends the process.process.nextTick(done, err)inapp.render: the test failed, and the run also had an unhandled error.view.pathunset afternew View(), makeslookuptake a callback, and removesresolve.view cacheoff do file I/O on every render. Production turnsview cacheon.Proof
npm run lint,npm run typecheckandnpm run test:typesare 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:bug()test before this PR.src/request.tsfails 18 tests: the regression test, 15 edge cases and 2 differential scenarios;src/view.tsfails 10 tests: the regression test, 7 edge cases and 2 differential scenarios.Host: tobi.ferrets.example.com.gives["example", "ferrets", "tobi"];app.engine('HTML')withuser.htmlthrowsCannot find module 'html'.Benchmark
Not run. The benchmark workflows are paused, and bug fixes don't wait on them.
Risks / follow-ups
x.HTMLreaching therequire()fallback, now gets the registered engine. Therequire()fallback still uses the extension as written (require('EJS')).app.engines.fs.*Sync;