Skip to content

Fix view engine resolution for view names ending in a dot#7392

Open
aryamirani wants to merge 1 commit into
expressjs:masterfrom
aryamirani:fix/view-name-dot-extension
Open

Fix view engine resolution for view names ending in a dot#7392
aryamirani wants to merge 1 commit into
expressjs:masterfrom
aryamirani:fix/view-name-dot-extension

Conversation

@aryamirani

Copy link
Copy Markdown

Summary

Fixes #7350 where calling res.render('index.') or app.render('index.') throws an opaque synchronous TypeError [ERR_INVALID_ARG_VALUE]: The argument 'id' must be a non-empty string. Received '' instead of resolving the view or reporting a clean view lookup error.

Root Cause

When a view name ends in a dot (such as 'index.'), path.extname('index.') returns '.'.
In lib/view.js, this.ext is set to '.'. Because '.' is truthy, !this.ext evaluates to false, skipping the defaultEngine resolution logic. View then attempts to load an engine via require(this.ext.slice(1)) which passes require(), throwing a Node TypeError.

Solution

Treat '.' as an unprovided extension when engines['.'] is not explicitly registered. This allows fallback to defaultEngine (or returning a clean view lookup error).

Test Coverage

Added unit test in test/app.render.js verifying that app.render('rawr.') returns a clean lookup error message (Failed to lookup view "rawr.") when view engine is set.

When a view name ends in a dot (e.g. 'index.'), path.extname returns '.',
causing mod to evaluate to an empty string ('' '') and throwing an opaque
TypeError [ERR_INVALID_ARG_VALUE] when require('') is called inside View constructor.

This change treats '.' as an unprovided extension when engines['.'] is not
explicitly registered, allowing view engine fallback to defaultEngine or
returning a clean view lookup error.

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

Labels

None yet

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 "."

1 participant