Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ app.engine = function engine(ext, fn) {
? '.' + ext
: ext;

// store engine
this.engines[extension] = fn;
// store engine, normalizing extension to lowercase for
// case-insensitive matching with file extensions
this.engines[extension.toLowerCase()] = fn;

return this;
};
Expand Down
6 changes: 3 additions & 3 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function View(name, options) {
var opts = options || {};

this.defaultEngine = opts.defaultEngine;
this.ext = extname(name);
this.ext = extname(name).toLowerCase();
this.name = name;
this.root = opts.root;

Expand All @@ -65,9 +65,9 @@ function View(name, options) {

if (!this.ext) {
// get extension from default engine name
this.ext = this.defaultEngine[0] !== '.'
this.ext = (this.defaultEngine[0] !== '.'
? '.' + this.defaultEngine
: this.defaultEngine;
: this.defaultEngine).toLowerCase();

fileName += this.ext;
}
Expand Down
29 changes: 29 additions & 0 deletions test/app.engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,34 @@ describe('app', function(){
done();
})
})

it('should match engine registered with uppercase ext to lowercase file', function(done){
var app = express();

app.set('views', path.join(__dirname, 'fixtures'))
app.engine('HTML', render);
app.locals.user = { name: 'tobi' };

app.render('user.html', function(err, str){
if (err) return done(err);
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})

it('should match engine registered with mixed case ext', function(done){
var app = express();

app.set('views', path.join(__dirname, 'fixtures'))
app.engine('Html', render);
app.set('view engine', 'Html');
app.locals.user = { name: 'tobi' };

app.render('user', function(err, str){
if (err) return done(err);
assert.strictEqual(str, '<p>tobi</p>')
done();
})
})
})
})