Skip to content

fix(view): treat a view name ending in "." as extensionless - #7414

Closed
bilashcse wants to merge 5 commits into
expressjs:masterfrom
bilashcse:fix/view-trailing-dot
Closed

fix(view): treat a view name ending in "." as extensionless#7414
bilashcse wants to merge 5 commits into
expressjs:masterfrom
bilashcse:fix/view-trailing-dot

Conversation

@bilashcse

Copy link
Copy Markdown

Closes #7350

Problem

path.extname('index.') returns '.', which is truthy but is not a usable extension. View assigned this.ext = extname(name) directly, so for a view name ending in a dot the if (!this.ext) default-engine fallback was skipped, this.ext.slice(1) evaluated to an empty string, and the engine loader called require(''). That throws TypeError [ERR_INVALID_ARG_VALUE] synchronously out of app.render() / res.render() instead of surfacing the usual lookup error through the callback.

Fix

Treat a lone '.' returned by path.extname() as "no extension", so a name with a trailing dot follows the same code path as any other extensionless name. With view engine set, the default engine is appended and lookup fails normally, producing Failed to lookup view "user.". Without view engine set, the existing No default engine was specified and no extension was provided. error is raised. An inline comment above the change documents the edge case.

Tests

test/app.render.js asserts that app.render('user.', cb) no longer throws and that the callback receives a lookup error. test/res.render.js asserts that res.render('user.') responds 500 with Failed to lookup view "user." when view engine is set, and 500 with No default engine was specified when it is not.

Notes

Behaviour is unchanged for any name that does not end in a dot, because path.extname() only returns '.' in that case.

path.extname() returns '.' for a view name ending in a dot, which is truthy but is not a usable extension. That left View#ext as '.', so the engine lookup called require('') and threw an opaque ERR_INVALID_ARG_VALUE past app.render()'s callback. Treat it as no extension instead.

Closes expressjs#7350
@krzysdz

krzysdz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #7351

@krzysdz krzysdz marked this as a duplicate of #7351 Aug 10, 2026
@krzysdz krzysdz closed this Aug 10, 2026
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