summaryrefslogtreecommitdiffstats
path: root/lib/utils/path.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-09-15 14:21:27 +0200
committerSamy Pessé <samypesse@gmail.com>2015-09-15 14:21:27 +0200
commit6732957e42350b3aefa4b1c80371baea92950651 (patch)
tree1605473bf22c7e4ab90a6cc9bebf5cb807fa1d90 /lib/utils/path.js
parent5f56098ae7fae80a4dd75a944c38201560b480c6 (diff)
parent1fd00068595dfced5a0f16ac05ae2553d09608bc (diff)
downloadgitbook-6732957e42350b3aefa4b1c80371baea92950651.zip
gitbook-6732957e42350b3aefa4b1c80371baea92950651.tar.gz
gitbook-6732957e42350b3aefa4b1c80371baea92950651.tar.bz2
Merge pull request #930 from GitbookIO/jshint
Add config for jshint and fix lint errors
Diffstat (limited to 'lib/utils/path.js')
-rw-r--r--lib/utils/path.js23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/utils/path.js b/lib/utils/path.js
index d5b98f7..5285896 100644
--- a/lib/utils/path.js
+++ b/lib/utils/path.js
@@ -1,5 +1,5 @@
var _ = require("lodash");
-var path = require('path');
+var path = require("path");
// Return true if file path is inside a folder
function isInRoot(root, filename) {
@@ -10,28 +10,29 @@ function isInRoot(root, filename) {
// Resolve paths in a specific folder
// Throw error if file is outside this folder
function resolveInRoot(root) {
- var input = _.chain(arguments)
+ var input, result, err;
+
+ input = _.chain(arguments)
.toArray()
.slice(1)
- .reduce(function(current, p, i) {
- // Handle path relative to book root ('/README.md')
- if (p[0] == '/' || p[0] == '\\') return p.slice(1);
+ .reduce(function(current, p) {
+ // Handle path relative to book root ("/README.md")
+ if (p[0] == "/" || p[0] == "\\") return p.slice(1);
return current? path.join(current, p) : path.normalize(p);
- }, '')
+ }, "")
.value();
- var result = path.resolve(root, input);
+ result = path.resolve(root, input);
if (!isInRoot(root, result)) {
- err = new Error("EACCESS: '" + result + "' not in '" + root + "'");
+ err = new Error("EACCESS: \"" + result + "\" not in \"" + root + "\"");
err.code = "EACCESS";
throw err;
}
- return result
-};
-
+ return result;
+}
module.exports = {
isInRoot: isInRoot,