From 5ac27535d965186372b4a4ff4cd9e6493e83f413 Mon Sep 17 00:00:00 2001 From: Martin Murphy Date: Sat, 1 Feb 2014 16:54:51 -0600 Subject: [PATCH 1/4] Attempt to get the last parammissing to match the longer route. --- lib/router.js | 5 ++++- spec/routerSpec.coffee | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/router.js b/lib/router.js index ce5595f..91ad5ab 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; @@ -131,7 +133,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 From 9fe3549526ec0fe9a138cbc1ac267aa262cc6da2 Mon Sep 17 00:00:00 2001 From: Martin Murphy Date: Fri, 28 Feb 2014 13:24:07 -0600 Subject: [PATCH 2/4] Last parameter replacement pattern --- lib/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/router.js b/lib/router.js index 91ad5ab..8608284 100644 --- a/lib/router.js +++ b/lib/router.js @@ -21,7 +21,7 @@ var DESTROY: httpMethod.DELETE }, LAST_PARAM_DETECTION = /(\/:[\w\d]+)$/, - LAST_PARAM_REPLACEMENT = /\/?([^\/\?]*)$/, + LAST_PARAM_REPLACEMENT = "?/([^\/\?]*)$", PATH_PARAMETER_REPLACEMENT = "([^\/\?]+)", PATH_PARAMETERS = /:([\w\d]+)/g; From ba94c8c11bb206a9517766422b44d809f9806eea Mon Sep 17 00:00:00 2001 From: Martin Murphy Date: Sun, 4 May 2014 22:05:38 -0500 Subject: [PATCH 3/4] Upgrade parted --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0f2a657..4a0275e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bogart", "description": "Fast JSGI web framework taking inspiration from Sinatra", - "version": "0.5.22", + "version": "0.5.23", "keywords": ["bogart", "framework", "sinatra", "REST"], "author": "Nathan Stott ", "email": "nathan.stott@whiteboard-it.com", @@ -22,7 +22,7 @@ "mustache": "0.7.2", "underscore": ">=1.4.4", "node-uuid": ">=1.2.0", - "parted": "=0.1.1", + "parted": "git://github.com/soitgoes/parted.git#v0.1.2", "oauth": "=0.9.5", "request": "=2.2.9", "commander": "*", From c28882609db1e4dc66de2329d873b5a4e4ec24c4 Mon Sep 17 00:00:00 2001 From: Martin Murphy Date: Sat, 16 May 2015 16:44:06 -0500 Subject: [PATCH 4/4] Fix undefined array bug --- lib/flash/flashIdCookieProvider.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +};