fix(view): treat a view name ending in "." as extensionless - #7414
Closed
bilashcse wants to merge 5 commits into
Closed
fix(view): treat a view name ending in "." as extensionless#7414bilashcse wants to merge 5 commits into
bilashcse wants to merge 5 commits into
Conversation
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
Contributor
|
Duplicate of #7351 |
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.
Closes #7350
Problem
path.extname('index.')returns'.', which is truthy but is not a usable extension.Viewassignedthis.ext = extname(name)directly, so for a view name ending in a dot theif (!this.ext)default-engine fallback was skipped,this.ext.slice(1)evaluated to an empty string, and the engine loader calledrequire(''). That throwsTypeError [ERR_INVALID_ARG_VALUE]synchronously out ofapp.render()/res.render()instead of surfacing the usual lookup error through the callback.Fix
Treat a lone
'.'returned bypath.extname()as "no extension", so a name with a trailing dot follows the same code path as any other extensionless name. Withview engineset, the default engine is appended and lookup fails normally, producingFailed to lookup view "user.". Withoutview engineset, the existingNo 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.jsasserts thatapp.render('user.', cb)no longer throws and that the callback receives a lookup error.test/res.render.jsasserts thatres.render('user.')responds 500 withFailed to lookup view "user."whenview engineis set, and 500 withNo default engine was specifiedwhen 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.