From f8687884178fd5ac511b934421ace0fc20eb9a58 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 10 Feb 2021 01:12:43 -0500 Subject: [PATCH] Remove unnecessary `path.normalize()` calls `path.join()` already normalizes. --- src/node/hooks/express/tests.js | 5 ++--- src/node/utils/AbsolutePaths.js | 2 +- src/node/utils/Minify.js | 4 ++-- src/node/utils/Settings.js | 2 +- src/node/utils/caching_middleware.js | 2 +- src/static/js/pluginfw/plugins.js | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/node/hooks/express/tests.js b/src/node/hooks/express/tests.js index 825c495ca..8c2e8edb5 100644 --- a/src/node/hooks/express/tests.js +++ b/src/node/hooks/express/tests.js @@ -29,8 +29,7 @@ exports.expressCreateServer = (hookName, args, cb) => { res.end(`var specs_list = ${JSON.stringify(files)};\n`); }); - // path.join seems to normalize by default, but we'll just be explicit - const rootTestFolder = path.normalize(path.join(npm.root, '../tests/frontend/')); + const rootTestFolder = path.join(npm.root, '../tests/frontend/'); const url2FilePath = (url) => { let subPath = url.substr('/tests/frontend'.length); @@ -39,7 +38,7 @@ exports.expressCreateServer = (hookName, args, cb) => { } subPath = subPath.split('?')[0]; - let filePath = path.normalize(path.join(rootTestFolder, subPath)); + let filePath = path.join(rootTestFolder, subPath); // make sure we jail the paths to the test folder, otherwise serve index if (filePath.indexOf(rootTestFolder) !== 0) { diff --git a/src/node/utils/AbsolutePaths.js b/src/node/utils/AbsolutePaths.js index 5b364ed80..8ca17ba18 100644 --- a/src/node/utils/AbsolutePaths.js +++ b/src/node/utils/AbsolutePaths.js @@ -132,7 +132,7 @@ exports.makeAbsolute = (somePath) => { return somePath; } - const rewrittenPath = path.normalize(path.join(exports.findEtherpadRoot(), somePath)); + const rewrittenPath = path.join(exports.findEtherpadRoot(), somePath); absPathLogger.debug(`Relative path "${somePath}" can be rewritten to "${rewrittenPath}"`); return rewrittenPath; diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 2a7ee2bfa..c9d263406 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -101,7 +101,7 @@ const minify = async (req, res) => { let filename = req.params.filename; // No relative paths, especially if they may go up the file hierarchy. - filename = path.normalize(path.join(ROOT_DIR, filename)); + filename = path.join(ROOT_DIR, filename); filename = filename.replace(/\.\./g, ''); if (filename.indexOf(ROOT_DIR) === 0) { @@ -198,7 +198,7 @@ const getAceFile = async () => { await Promise.all(filenames.map(async (filename) => { // Hostname "invalid.invalid" is a dummy value to allow parsing as a URI. const baseURI = 'http://invalid.invalid'; - let resourceURI = baseURI + path.normalize(path.join('/static/', filename)); + let resourceURI = baseURI + path.join('/static/', filename); resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?) const [status, , body] = await requestURI(resourceURI, 'GET', {}); diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 0da117a59..202e80c60 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -719,7 +719,7 @@ exports.reloadSettings = () => { } // informative variable, just for the log messages - let skinPath = path.normalize(path.join(skinBasePath, exports.skinName)); + let skinPath = path.join(skinBasePath, exports.skinName); // what if someone sets skinName == ".." or "."? We catch him! if (absolutePaths.isSubdir(skinBasePath, skinPath) === false) { diff --git a/src/node/utils/caching_middleware.js b/src/node/utils/caching_middleware.js index ff25513cc..23122342a 100644 --- a/src/node/utils/caching_middleware.js +++ b/src/node/utils/caching_middleware.js @@ -44,7 +44,7 @@ try { _crypto = undefined; } -let CACHE_DIR = path.normalize(path.join(settings.root, 'var/')); +let CACHE_DIR = path.join(settings.root, 'var/'); CACHE_DIR = existsSync(CACHE_DIR) ? CACHE_DIR : undefined; const responseCache = {}; diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 8323cfc7c..48ae4c92b 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -32,7 +32,7 @@ exports.formatHooks = (hookSetName) => { const callInit = async () => { await Promise.all(Object.keys(defs.plugins).map(async (pluginName) => { const plugin = defs.plugins[pluginName]; - const epInit = path.normalize(path.join(plugin.package.path, '.ep_initialized')); + const epInit = path.join(plugin.package.path, '.ep_initialized'); try { await fs.stat(epInit); } catch (err) { @@ -48,7 +48,7 @@ exports.pathNormalization = (part, hookFnName, hookName) => { const functionName = (tmp.length > 1 ? tmp.pop() : null) || hookName; const moduleName = tmp.join(':') || part.plugin; const packageDir = path.dirname(defs.plugins[part.plugin].package.path); - const fileName = path.normalize(path.join(packageDir, moduleName)); + const fileName = path.join(packageDir, moduleName); return `${fileName}:${functionName}`; };