Skip to content

Commit

Permalink
Fix failing test case where uri.host was null.
Browse files Browse the repository at this point in the history
Font names are passed in without a host name or protocol, so
trying to use `uri.host` was resulting in "null" being inserted
into the path. This fixes that by checking whether `uri.host` is
falsey before using it.

Also, it was getting hard to read, so factored out some
expressions into their own variables.
  • Loading branch information
zerebubuth committed May 8, 2015
1 parent 3ccdaef commit 74b8951
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ middleware.normalizePaths = function(req, res, next) {
if (!req.query[key]) return;
var uri = tm.parse(req.query[key]);
var is_windows = (req.query[key].indexOf(':\\') >= 0);
req.query[key] = (uri.protocol ? uri.protocol + '//' : '') + (is_windows ? '' : uri.host) + uri.dirname;
var protocol = uri.protocol ? uri.protocol + '//' : '';
var host = (is_windows || !uri.host) ? '' : uri.host;
req.query[key] = protocol + host + uri.dirname;
});
['id','source'].forEach(function(key) {
if (!req.body || !req.body[key]) return;
Expand All @@ -28,7 +30,9 @@ middleware.normalizePaths = function(req, res, next) {
// field, so we need to exclude the host from the normalised path
// when we detect that it's a windows path.
var is_windows = (req.body[key].indexOf(':\\') >= 0);
req.body[key] = (uri.protocol ? uri.protocol + '//' : '') + (is_windows ? '' : uri.host) + uri.dirname;
var protocol = uri.protocol ? uri.protocol + '//' : '';
var host = (is_windows || !uri.host) ? '' : uri.host;
req.body[key] = protocol + host + uri.dirname;
});
next();
};
Expand Down

0 comments on commit 74b8951

Please sign in to comment.