module: fix createRequireFromPath() slash logic

The trailing slash detection logic in createRequireFromPath()
seemed slightly incorrect. This commit reworks the logic.

PR-URL: https://github.com/nodejs/node/pull/27634
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
cjihrig 2019-05-09 20:25:28 -04:00
parent 6be5c3bdae
commit ef51cc8ac9
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5

View File

@ -838,7 +838,7 @@ Module.runMain = function() {
function createRequireFromPath(filename) {
// Allow a directory to be passed as the filename
const trailingSlash =
filename.endsWith(path.sep) || path.sep !== '/' && filename.endsWith('\\');
filename.endsWith('/') || (isWindows && filename.endsWith('\\'));
const proxyPath = trailingSlash ?
path.join(filename, 'noop.js') :