fix: throw clean lookup error for view names ending with a dot - #7420
Closed
haoku123 wants to merge 1 commit into
Closed
fix: throw clean lookup error for view names ending with a dot#7420haoku123 wants to merge 1 commit into
haoku123 wants to merge 1 commit into
Conversation
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
This was referenced Aug 14, 2026
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #7350
A view name ending in
.makespath.extname('index.')return'.', which is truthy, so the "no extension → use default engine" fallback inlib/view.jsis skipped.this.extstays'.',this.ext.slice(1)becomes'', andrequire('')is called, throwing an opaqueERR_INVALID_ARG_VALUETypeError 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 usualFailed 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:Tests
Added
when the view name ends with a "."totest/app.render.jsverifying the callback receives the standardFailed to lookup view "user."error rather thanERR_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.