Skip to content

Commit

Permalink
change filepath function to work on win.
Browse files Browse the repository at this point in the history
  • Loading branch information
Franček Prijatelj committed Sep 8, 2011
1 parent d3b9783 commit 53df377
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/paperboy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ var


exports.filepath = function (webroot, url) {
var pathSep=process.platform =='win32' ? '\\' : '/'
// Unescape URL to prevent security holes
url = decodeURIComponent(url);
// Strip nullbytes (they can make us believe that the file extension isn't the one it really is)
url = url.replace(/\0/g, '');
// Append index.html if path ends with '/'
fp = path.normalize(path.join(webroot, (url.match(/\/$/)=='/') ? url+'index.html' : url));
// Sanitize input, make sure people can't use .. to get above webroot
if (!/\/|\\$/.test(webroot[webroot.length - 1])) { webroot = path.normalize(webroot + '/'); }
if (webroot[webroot.length - 1] !== pathSep) webroot += pathSep;
if (fp.substr(0, webroot.length) != webroot)
return(['Permission Denied', null]);
else
return([null, fp]);
return([null, fp.replace('/',pathSep)]);
};

exports.streamFile = function (filepath, headerFields, stat, res, req, emitter) {
Expand Down

0 comments on commit 53df377

Please sign in to comment.