diff --git a/.gitignore b/.gitignore index f80df97..8da2c81 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ server/test-dir/* !server/test-dir/sub-dir/main.css !server/test-dir/index.html node_modules +package-lock.json \ No newline at end of file diff --git a/lib/helpers/lock-directory.js b/lib/helpers/lock-directory.js index c8920c5..670c9eb 100644 --- a/lib/helpers/lock-directory.js +++ b/lib/helpers/lock-directory.js @@ -1,11 +1,11 @@ module.exports = function () { let paths = [...arguments]; - return new Promise((reslove, reject) => { + return new Promise((resolve, reject) => { paths.forEach((path, i) => { - if (path.match('../')) { + if (path.includes('../')) { reject('can\'t access directories above base dir'); } }); - reslove(); + resolve(); }); }; diff --git a/lib/routes/append.js b/lib/routes/append.js index c6776f6..bfdd958 100644 --- a/lib/routes/append.js +++ b/lib/routes/append.js @@ -13,6 +13,7 @@ var lockDirectory = require('../helpers/lock-directory'); */ module.exports = (req, res) => { const filePath = path.join(res.locals.baseDir, req.body.path); + const dirPath = path.dirname(filePath); lockDirectory(req.body.path) .then(() => fsp.ensureDir(dirPath)) .then(() => fsp.appendFile(filePath, req.body.contents))