Skip to content

fix: throw clean lookup error for view names ending with a dot - #7420

Closed
haoku123 wants to merge 1 commit into
expressjs:masterfrom
haoku123:fix/view-trailing-dot
Closed

fix: throw clean lookup error for view names ending with a dot#7420
haoku123 wants to merge 1 commit into
expressjs:masterfrom
haoku123:fix/view-trailing-dot

Conversation

@haoku123

Copy link
Copy Markdown

Problem

Closes #7350

A view name ending in . makes path.extname('index.') return '.', which is truthy, so the "no extension → use default engine" fallback in lib/view.js is skipped. this.ext stays '.', this.ext.slice(1) becomes '', and require('') is called, throwing an opaque ERR_INVALID_ARG_VALUE TypeError instead of resolving the view or reporting a clean lookup error.

Via res.render('index.') inside a route, the same error surfaces as an opaque 500 in the error handler instead of the usual Failed to lookup view "index." error.

Solution

Treat a bare . as no extension so the default engine is applied and view resolution reports a clean lookup error through the callback:

// a name ending in "." yields a bare "." from extname(), which is not a
// usable extension; treat it as no extension so the default engine is
// applied and a clean lookup error is reported instead of require("")
if (this.ext === '.') {
  this.ext = '';
}

Tests

Added when the view name ends with a "." to test/app.render.js verifying the callback receives the standard Failed to lookup view "user." error rather than ERR_INVALID_ARG_VALUE. Full suite passes (npm test → 1264 passing), lint clean.

Note

Re-implements the stalled #7351 (author inactive since July) on current master, with the same behavior and test coverage.

A view name ending in '.' makes extname() return '.', which is truthy,
so the no-extension fallback was skipped and require('') was called with
an empty module id, surfacing an opaque ERR_INVALID_ARG_VALUE TypeError
from res.render()/app.render() instead of the usual view lookup error.

Treat a bare '.' as no extension so the default engine is applied and
the view resolution reports a clean 'Failed to lookup view' error via
the callback.

Fixes expressjs#7350
@krzysdz

krzysdz commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

PRs can always be picked up by maintainers (if the appropriate option is selected). I don't see any requested changes in #7351, so I'll close this as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

res.render()/app.render() throws opaque TypeError for a view name ending in "."

2 participants