From 21eb59e7e4466c151ca4d20f6e9f852d9d40cb59 Mon Sep 17 00:00:00 2001 From: Pradip-Garai Date: Sun, 12 Jul 2026 11:48:56 +0530 Subject: [PATCH] fix(view): handle view names ending with a dot Avoid calling require("") with an empty string when the resolved extension is a single dot (e.g., "index."). This prevents an opaque TypeError and correctly falls back to resolving the view or yielding a clean lookup error. Also adds an automated regression test in test/app.render.js. --- lib/view.js | 4 ++++ test/app.render.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/view.js b/lib/view.js index d66b4a2d89c..10d2976f7be 100644 --- a/lib/view.js +++ b/lib/view.js @@ -55,6 +55,10 @@ function View(name, options) { this.defaultEngine = opts.defaultEngine; this.ext = extname(name); this.name = name; + + if (this.ext === '.') { + this.ext = ''; + } this.root = opts.root; if (!this.ext && !this.defaultEngine) { diff --git a/test/app.render.js b/test/app.render.js index bd65ce1035b..7b6724d2994 100644 --- a/test/app.render.js +++ b/test/app.render.js @@ -90,6 +90,18 @@ describe('app', function(){ done(); }); }) + + it('should provide a helpful error when view name ends with a dot', function(done){ + var app = createApp(); + app.set('view engine', 'tmpl'); + + app.set('views', path.join(__dirname, 'fixtures')) + app.render('rawr.', function (err) { + assert.ok(err) + assert.equal(err.message, 'Failed to lookup view "rawr." in views directory "' + path.join(__dirname, 'fixtures') + '"') + done(); + }); + }) }) describe('when an error occurs', function(){