From b1d558b3fc1b99c0be297e0f61da0b4a077ececb Mon Sep 17 00:00:00 2001 From: Mayank Gautam Date: Mon, 17 Feb 2020 22:26:16 +0530 Subject: [PATCH 1/5] Added safegaurd against invalid project id in the method getFileContent --- server/controllers/file.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index 69625a18..f915f613 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -110,7 +110,7 @@ export function deleteFile(req, res) { export function getFileContent(req, res) { Project.findById(req.params.project_id, (err, project) => { - if (err) { + if (err || project == null) { res.status(404).send({ success: false, message: 'Project with that id does not exist.' }); return; } From bea3119147a413fbd5598b167ec8bad5ae0d6a88 Mon Sep 17 00:00:00 2001 From: Mayank Gautam Date: Tue, 18 Feb 2020 09:06:06 +0530 Subject: [PATCH 2/5] added undefined filePath check in the method resolvePathToFile --- server/utils/filePath.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/utils/filePath.js b/server/utils/filePath.js index 027b0e13..6a1ea673 100644 --- a/server/utils/filePath.js +++ b/server/utils/filePath.js @@ -1,4 +1,8 @@ export function resolvePathToFile(filePath, files) { + if (typeof filePath === 'undefined') { + return false; + } + const filePathArray = filePath.split('/'); let resolvedFile; let currentFile = files.find(file => file.name === 'root'); From 87548486998d2670644cff1c916522ed7f3b8498 Mon Sep 17 00:00:00 2001 From: Mayank Gautam Date: Mon, 17 Feb 2020 22:26:16 +0530 Subject: [PATCH 3/5] Added safegaurd against invalid project id in the method getFileContent --- server/controllers/file.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index b70f33a0..3762ffe7 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -111,7 +111,7 @@ export function deleteFile(req, res) { export function getFileContent(req, res) { Project.findById(req.params.project_id, (err, project) => { - if (err) { + if (err || project == null) { res.status(404).send({ success: false, message: 'Project with that id does not exist.' }); return; } From c9b40bbd74151f56218ccad5e5f4f6aff938cd4d Mon Sep 17 00:00:00 2001 From: Mayank Gautam Date: Tue, 18 Feb 2020 09:06:06 +0530 Subject: [PATCH 4/5] added undefined filePath check in the method resolvePathToFile --- server/utils/filePath.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/utils/filePath.js b/server/utils/filePath.js index 027b0e13..6a1ea673 100644 --- a/server/utils/filePath.js +++ b/server/utils/filePath.js @@ -1,4 +1,8 @@ export function resolvePathToFile(filePath, files) { + if (typeof filePath === 'undefined') { + return false; + } + const filePathArray = filePath.split('/'); let resolvedFile; let currentFile = files.find(file => file.name === 'root'); From 416824ad56ba8375430adfefc3d3284b13b75b5c Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Mon, 30 Mar 2020 17:07:10 -0400 Subject: [PATCH 5/5] Code style changes to use === and comparison to undefined --- server/controllers/file.controller.js | 2 +- server/utils/filePath.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index 3762ffe7..4ccb6db2 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -111,7 +111,7 @@ export function deleteFile(req, res) { export function getFileContent(req, res) { Project.findById(req.params.project_id, (err, project) => { - if (err || project == null) { + if (err || project === null) { res.status(404).send({ success: false, message: 'Project with that id does not exist.' }); return; } diff --git a/server/utils/filePath.js b/server/utils/filePath.js index 6a1ea673..4e12a82c 100644 --- a/server/utils/filePath.js +++ b/server/utils/filePath.js @@ -1,5 +1,5 @@ export function resolvePathToFile(filePath, files) { - if (typeof filePath === 'undefined') { + if (filePath === undefined) { return false; }