diff --git a/lib/flash/flashIdCookieProvider.js b/lib/flash/flashIdCookieProvider.js index 7ab4255..97c8da6 100644 --- a/lib/flash/flashIdCookieProvider.js +++ b/lib/flash/flashIdCookieProvider.js @@ -59,9 +59,9 @@ CookieIdProvider.prototype.clear = function(req, res, flashId) { res.headers["Set-Cookie"] = res.headers["Set-Cookie"].filter(function(el) { return !(new RegExp("^" + flashCookieName + "=").test(el)); - }); + }) || []; res.headers["Set-Cookie"].push(clearCookie); } return res; -}; \ No newline at end of file +}; diff --git a/lib/router.js b/lib/router.js index a3dad73..440d186 100644 --- a/lib/router.js +++ b/lib/router.js @@ -20,6 +20,8 @@ var UPDATE: httpMethod.PUT, DESTROY: httpMethod.DELETE }, + LAST_PARAM_DETECTION = /(\/:[\w\d]+)$/, + LAST_PARAM_REPLACEMENT = "?/([^\/\?]*)$", PATH_PARAMETER_REPLACEMENT = "([^\/\?]+)", PATH_PARAMETERS = /:([\w\d]+)/g; @@ -132,7 +134,8 @@ Router.prototype.route = function(method, path /*, handlers... */) { paramNames = path.match(PATH_PARAMETERS) || []; paramNames = paramNames.map(function(x) { return x.substring(1); }); - path = new RegExp("^"+path.replace(/\./, '\\.').replace(/\*/g, '(.+)').replace(PATH_PARAMETERS, PATH_PARAMETER_REPLACEMENT)+'$'); + path = new RegExp("^"+path.replace(/\./, '\\.').replace(/\*/g, '(.+)').replace(LAST_PARAM_DETECTION, LAST_PARAM_REPLACEMENT).replace(PATH_PARAMETERS, PATH_PARAMETER_REPLACEMENT)); + console.log(path); } route = makeRoute({ path: path, paramNames: paramNames, apps: apps, originalPath: originalPath }); diff --git a/spec/routerSpec.coffee b/spec/routerSpec.coffee index 5758af9..d4e5ef6 100644 --- a/spec/routerSpec.coffee +++ b/spec/routerSpec.coffee @@ -197,6 +197,24 @@ describe 'regex route', -> expect(res).toBe routeRes done() +describe 'request with an empty param', -> + res = null + routeRes = null + + beforeEach -> + router = bogart.router() + routeRes = bogart.html 'hello' + + router.get '/foo/:bar', (req) -> + routeRes + + res = router() new MockRequest('/foo') + + it 'should still match a variatic route', (done) -> + q.when res, (res) -> + expect(res).toBe routeRes + done() + describe 'request path with encoded slashes', -> res = null routeRes = null