Skip to content

fix: make view engine extension matching case-insensitive#7051

Open
erdinccurebal wants to merge 1 commit intoexpressjs:masterfrom
erdinccurebal:fix/case-insensitive-view-engine-ext
Open

fix: make view engine extension matching case-insensitive#7051
erdinccurebal wants to merge 1 commit intoexpressjs:masterfrom
erdinccurebal:fix/case-insensitive-view-engine-ext

Conversation

@erdinccurebal
Copy link

Summary

  • app.engine('Eta', fn) stored the engine under .Eta, but path.extname('search.eta') returns .eta, causing a lookup miss and triggering an unnecessary require() fallback.
  • This normalizes extensions to lowercase in app.engine() and the View constructor so that engine registration and file extension matching are case-insensitive.

Before

app.engine('Eta', Eta.renderFile);
console.log(app.engines); // { '.Eta': [Function: renderFile] }

// When rendering 'search.eta':
// path.extname('search.eta') => '.eta'
// app.engines['.eta'] => undefined (BUG: stored as '.Eta')
// Falls through to require('eta').__express

After

app.engine('Eta', Eta.renderFile);
console.log(app.engines); // { '.eta': [Function: renderFile] }

// When rendering 'search.eta':
// path.extname('search.eta') => '.eta'
// app.engines['.eta'] => [Function: renderFile] (MATCH)

Changes

  • lib/application.js: normalize extension to lowercase in app.engine()
  • lib/view.js: normalize this.ext to lowercase in View constructor (both from filename and from defaultEngine)
  • test/app.engine.js: 2 new tests for uppercase and mixed-case engine extensions

Test plan

  • Added test: engine registered with uppercase ext matches lowercase file
  • Added test: engine registered with mixed case ext works with view engine setting
  • All 1246 tests pass (1244 existing + 2 new)

Fixes #4594

When registering a view engine with a capitalized extension
(e.g. app.engine('Eta', fn)), Express stored it as '.Eta' but
file lookups returned '.eta' from path.extname(), causing a
mismatch. This normalizes extensions to lowercase in both
app.engine() and the View constructor so that engine registration
and file extension matching are case-insensitive.

Fixes expressjs#4594
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.

1 participant