From 1d01741ae7fabec1904c8c84eaddb5dfa73b3b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 30 Jan 2022 18:51:28 -0500 Subject: [PATCH] fix: #10208, don't use leading slash in directory names change to use decodeURIComponent in utils.params --- public/src/utils.js | 4 ++-- src/controllers/admin/uploads.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/src/utils.js b/public/src/utils.js index a505398545..f2f63e219c 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -645,10 +645,10 @@ params.forEach(function (param) { const val = param.split('='); - let key = decodeURI(val[0]); + let key = decodeURIComponent(val[0]); const value = ( options.disableToType || - options.skipToType[key] ? decodeURI(val[1]) : utils.toType(decodeURI(val[1])) + options.skipToType[key] ? decodeURIComponent(val[1]) : utils.toType(decodeURIComponent(val[1])) ); if (key) { diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js index 2fb3d2741f..e0cdb34930 100644 --- a/src/controllers/admin/uploads.js +++ b/src/controllers/admin/uploads.js @@ -87,15 +87,16 @@ async function filesToData(currentDir, files) { } async function getFileData(currentDir, file) { - const stat = await fs.promises.stat(path.join(currentDir, file)); + const pathToFile = path.join(currentDir, file); + const stat = await fs.promises.stat(pathToFile); let filesInDir = []; if (stat.isDirectory()) { - filesInDir = await fs.promises.readdir(path.join(currentDir, file)); + filesInDir = await fs.promises.readdir(pathToFile); } const url = `${nconf.get('upload_url') + currentDir.replace(nconf.get('upload_path'), '')}/${file}`; return { name: file, - path: path.join(currentDir, file).replace(nconf.get('upload_path'), ''), + path: pathToFile.replace(path.join(nconf.get('upload_path'), '/'), ''), url: url, fileCount: Math.max(0, filesInDir.length - 1), // ignore .gitignore size: stat.size,