diff --git a/lib/bcoin/http.js b/lib/bcoin/http.js index f690725e..01a50113 100644 --- a/lib/bcoin/http.js +++ b/lib/bcoin/http.js @@ -256,34 +256,35 @@ HTTPServer.prototype._initRouter = function _initRouter() { return done(new Error('No routes found.')); (function next() { + var route, path, callback, compiled, matched; + + if (i === routes.length) + return done(new Error('Route not found.')); + + route = routes[i++]; + path = route.path; + callback = route.callback; + + if (!route.regex) { + compiled = compilePath(path); + route.regex = compiled.regex; + route.map = compiled.map; + } + + matched = route.regex.exec(req.pathname); + + if (!matched) + return next(); + + req.params = {}; + matched.slice(1).forEach(function(item, i) { + if (route.map[i]) + req.params[route.map[i]] = item; + req.params[i] = item; + }); + + // Avoid stack overflows utils.nextTick(function() { - var route, path, callback, compiled, matched; - - if (i === routes.length) - return done(new Error('Route not found.')); - - route = routes[i++]; - path = route.path; - callback = route.callback; - - if (!route.regex) { - compiled = compilePath(path); - route.regex = compiled.regex; - route.map = compiled.map; - } - - matched = route.regex.exec(req.pathname); - - if (!matched) - return next(); - - req.params = {}; - matched.slice(1).forEach(function(item, i) { - if (route.map[i]) - req.params[route.map[i]] = item; - req.params[i] = item; - }); - try { callback(req, res, next, _send); } catch (e) { diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index d750b306..cdbf3207 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -1421,7 +1421,11 @@ utils.ccmp = function(a, b) { var res = 0; var i; - assert(a.length === b.length); + assert(Buffer.isBuffer(a)); + assert(Buffer.isBuffer(b)); + + if (a.length !== b.length) + return false; for (i = 0; i < a.length; i++) res |= a[i] ^ b[i];