Remove unnecessary path.normalize() calls

`path.join()` already normalizes.
This commit is contained in:
Richard Hansen 2021-02-10 01:12:43 -05:00 committed by John McLear
parent 84c1d74f8b
commit f868788417
6 changed files with 9 additions and 10 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -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', {});

View file

@ -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) {

View file

@ -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 = {};

View file

@ -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}`;
};