Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 531152 - Regression from fix for recursive path paste
  • Loading branch information
squarti committed Feb 14, 2018
1 parent 05bc822 commit ad344ce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/orionode/lib/fileUtil.js
Expand Up @@ -499,6 +499,16 @@ function isProjectFile(file) {
function isWorkspaceFile(file) {
return file.workspaceDir === file.path;
}
function isParentOf(_filePath, _otherPath) {
var filePath = path.normalize(path.resolve(_filePath));
var otherPath = path.normalize(path.resolve(_otherPath));
var root = path.parse(otherPath).root;
while (otherPath !== root) {
otherPath = path.dirname(otherPath);
if (filePath === otherPath) return true;
}
return false;
}
/**
* Helper for fulfilling a file POST request (for example, copy, move, or create).
* @param {string} workspaceRoot The route of the /workspace handler (not including context path)
Expand Down Expand Up @@ -542,9 +552,9 @@ exports.handleFilePOST = function(workspaceRoot, fileRoot, req, res, destFile, m
var project = {};
if (isNonWrite) {
var sourceFile = getFile(req, api.decodeURIComponent(sourceUrl.replace(new RegExp("^"+fileRoot), "")));
// if (path.resolve(destFile.path).indexOf(path.resolve(sourceFile.path)) === 0) {
// return api.writeError(400, res, "The destination cannot be a descendent of the source location");
// }
if (isParentOf(sourceFile.path, destFile.path)) {
return api.writeError(400, res, "The destination cannot be a descendent of the source location");
}
return fs.stat(sourceFile.path, function(err, stats) {
if(err) {
if (err.code === 'ENOENT') {
Expand Down

0 comments on commit ad344ce

Please sign in to comment.