Permalink
Browse files

JSHint: prefer safer curly braces for if expressions

  • Loading branch information...
1 parent 886f545 commit a1df4dc8f19295e6cf50d3fdfc9a90a8062d9a48 @mcandre mcandre committed May 8, 2013
Showing with 27 additions and 9 deletions.
  1. +2 −1 .jshintrc
  2. +4 −1 example/basic.js
  3. +21 −7 lib/paperboy.js
View
3 .jshintrc
@@ -4,5 +4,6 @@
"maxerr": 10000,
"indent": 2,
"eqeqeq": true,
- "quotmark": true
+ "quotmark": true,
+ "curly": true
}
View
5 example/basic.js
@@ -32,7 +32,10 @@ http.createServer(function(req, res) {
function log(statCode, url, ip, err) {
var logStr = statCode + ' - ' + url + ' - ' + ip;
- if (err)
+
+ if (err) {
logStr += ' - ' + err;
+ }
+
console.log(logStr);
}
View
28 lib/paperboy.js
@@ -15,11 +15,16 @@ exports.filepath = function (webroot, url) {
// Append index.html if path ends with '/'
var 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 (webroot[webroot.length - 1] !== pathSep) webroot += pathSep;
- if (fp.substr(0, webroot.length) !== webroot)
+ if (webroot[webroot.length - 1] !== pathSep) {
+ webroot += pathSep;
+ }
+
+ if (fp.substr(0, webroot.length) !== webroot) {
return(['Permission Denied', null]);
- else
+ }
+ else {
return([null, fp.replace('/',pathSep)]);
+ }
};
exports.streamFile = function (filepath, headerFields, stat, res, req, emitter) {
@@ -31,8 +36,10 @@ exports.streamFile = function (filepath, headerFields, stat, res, req, emitter)
charset = exports.charsets[contentType];
process.nextTick( function() {
- if (charset)
+ if (charset) {
contentType += '; charset=' + charset;
+ }
+
headerFields['Content-Type'] = contentType;
var etag = '"' + stat.ino + '-' + stat.size + '-' + Date.parse(stat.mtime) +'"';
@@ -133,18 +140,25 @@ exports.deliver = function (webroot, req, res) {
//If file is in a directory outside of the webroot, deny the request
if (fpErr) {
statCode = 403;
- if (beforeCallback)
+
+ if (beforeCallback) {
beforeCallback();
+ }
+
errorCallback(403, 'Forbidden');
}
else {
fs.stat(filepath, function (err, stat) {
if( (err || !stat.isFile())) {
var exactErr = err || 'File not found';
- if (beforeCallback)
+
+ if (beforeCallback) {
beforeCallback();
- if (otherwiseCallback)
+ }
+
+ if (otherwiseCallback) {
otherwiseCallback(exactErr);
+ }
} else {
//The before callback can abort the transfer by returning false
var cancel = beforeCallback && (beforeCallback() === false);

0 comments on commit a1df4dc

Please sign in to comment.