Repository navigation
Open
abedmurrar/express
#69Labels
Description
Actually, in issue #4593, I provided Express the imported view engine instance.
I registered it as "Eta" (".Eta" internally), and Express did not use it for search.eta (because it was only looking for the ".eta" one), triggering the undesired automatic require.
app.engine("Eta", Eta.renderFile);
console.log(app.engines); // { '.Eta': [Function: renderFile] }
app.set("view engine", "Eta");function View(name, options) {
var opts = options || {};
this.defaultEngine = opts.defaultEngine;
this.ext = extname(name);
console.info("EXPRESS", [name, extname(name)]); // EXPRESS [ 'search.eta', '.eta' ]
this.name = name;
this.root = opts.root;Maybe it should normalize the ext to a single case?
Lines 293 to 307 in 5c4f3e7
| app.engine = function engine(ext, fn) { | |
| if (typeof fn !== 'function') { | |
| throw new Error('callback function required'); | |
| } | |
| // get file extension | |
| var extension = ext[0] !== '.' | |
| ? '.' + ext | |
| : ext; | |
| // store engine | |
| this.engines[extension] = fn; | |
| return this; | |
| }; |
Lines 52 to 88 in 5c4f3e7
| function View(name, options) { | |
| var opts = options || {}; | |
| this.defaultEngine = opts.defaultEngine; | |
| this.ext = extname(name); | |
| this.name = name; | |
| this.root = opts.root; | |
| if (!this.ext && !this.defaultEngine) { | |
| throw new Error('No default engine was specified and no extension was provided.'); | |
| } | |
| var fileName = name; | |
| if (!this.ext) { | |
| // get extension from default engine name | |
| this.ext = this.defaultEngine[0] !== '.' | |
| ? '.' + this.defaultEngine | |
| : this.defaultEngine; | |
| fileName += this.ext; | |
| } | |
| if (!opts.engines[this.ext]) { | |
| // load engine | |
| var mod = this.ext.substr(1) | |
| debug('require "%s"', mod) | |
| // default engine export | |
| var fn = require(mod).__express | |
| if (typeof fn !== 'function') { | |
| throw new Error('Module "' + mod + '" does not provide a view engine.') | |
| } | |
| opts.engines[this.ext] = fn | |
| } |
Reacted by mergerg
Activity
dougwilson commentedon May 17, 2021
Hm, that is a good point. I don't think such a change would be backwards compatible, but it could potentially be changed in a future major version of Express. I would like to leave this open to explore if folks are using the case sensitivity or not before we should decide on the change. Most file systems are not case insensitive.
webketje commentedon May 10, 2022
@dougwilson how would it not be backwards-compatible, except if a user foolishly specified 2 same-name view engines with only casing as a difference? Bumping as it may be a good time to take a decision on this issue with the v5 beta's?
To me it feels logical, just as an OS treats ..JPG & .jpg as the same ext.
But I would only support it if the
toLowerCaseis only required at the view engine definition level (not for each template)dougwilson commentedon May 10, 2022
Hi @webketje thanks for your input. We are trying to refrain from continuing to snowball the 5.x release with endless changes, and ideally just the last few on the list are all that is left. The change can just be targeted to the next major.
As for why it is not backwards compatible, as stated, most file systems (particularly on servers) are not case insensitive, and so you can actually have both a
index.fooand aindex.Foofile. Unfortunately we do not have insight in to all the ways folks use Express, and we have many examples and experience that a change like this will break folks. Since we value a stable API where you don't have to worry about upgrading Express, this is a breaking change, as it would change the behavior of view engine extension registration.fix: make view engine extension matching case-insensitive