Skip to content
Browse files

Merge pull request #28 from cimnine/master

Root Jail rejects all requests with 'Access denied'
  • Loading branch information...
2 parents 13b9372 + 6ec674e commit f9dca8f3ed493e9e831535a7e77841228e2e7064 Alexis Sellier committed
Showing with 7 additions and 7 deletions.
  1. +7 −7 lib/node-static.js
View
14 lib/node-static.js
@@ -20,7 +20,7 @@ this.indexStore = {};
this.Server = function (root, options) {
if (root && (typeof(root) === 'object')) { options = root, root = null }
- this.root = path.normalize(root || '.');
+ this.root = path.resolve(root || '.');
this.options = options || {};
this.cache = 3600;
@@ -77,7 +77,7 @@ this.Server.prototype.serveFile = function (pathname, status, headers, req, res)
var that = this;
var promise = new(events.EventEmitter);
- pathname = this.normalize(pathname);
+ pathname = this.resolve(pathname);
fs.stat(pathname, function (e, stat) {
if (e) {
@@ -124,7 +124,7 @@ this.Server.prototype.servePath = function (pathname, status, headers, req, res,
var that = this,
promise = new(events.EventEmitter);
- pathname = this.normalize(pathname);
+ pathname = this.resolve(pathname);
// Only allow GET and HEAD requests
if (req.method !== 'GET' && req.method !== 'HEAD') {
@@ -152,14 +152,14 @@ this.Server.prototype.servePath = function (pathname, status, headers, req, res,
}
return promise;
};
-this.Server.prototype.normalize = function (pathname) {
- return path.normalize(path.join(this.root, pathname));
+this.Server.prototype.resolve = function (pathname) {
+ return path.resolve(path.join(this.root, pathname));
};
this.Server.prototype.serve = function (req, res, callback) {
var that = this,
promise = new(events.EventEmitter);
-
- var pathname = url.parse(req.url).pathname;
+
+ var pathname = decodeURI(url.parse(req.url).pathname);
var finish = function (status, headers) {
that.finish(status, headers, req, res, promise, callback);

0 comments on commit f9dca8f

Please sign in to comment.
Something went wrong with that request. Please try again.