diff --git a/CHANGES.md b/CHANGES.md index 36cf3fab..990774bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +## Feb 21, 2012 +* Bug fix for https://github.com/ql-io/ql.io/issues/286 for 0.3 + ## Feb 14, 2012 * XSS issue for 404 response fixed. diff --git a/modules/console/app.js b/modules/console/app.js index 30569832..1b16b8ee 100644 --- a/modules/console/app.js +++ b/modules/console/app.js @@ -197,10 +197,16 @@ var Console = module.exports = function(config) { collectHttpQueryParams(req, holder, false); // find a route (i.e. associated cooked script) - var route = _.detect(verbRouteVariants, function(verbRouteVariant) { - return _.isEqual(_.intersection(_.keys(holder.params), _.keys(verbRouteVariant.query)), - _.keys(verbRouteVariant.query)); - }); + var route = _(verbRouteVariants).chain() + .filter(function (verbRouteVariant) { + return _.isEqual(_.intersection(_.keys(holder.params), _.keys(verbRouteVariant.query)), + _.keys(verbRouteVariant.query)) + }) + .reduce(function (match, route) { + return match == null ? + route : route.length > match.length ? route : match; + }, null) + .value(); if (!route) { res.writeHead(400, 'Bad input', { diff --git a/modules/console/package.json b/modules/console/package.json index dfa4e100..d88e75de 100755 --- a/modules/console/package.json +++ b/modules/console/package.json @@ -1,7 +1,7 @@ { "author": "ql.io", "name": "ql.io-console", - "version": "0.3.6", + "version": "0.3.7", "repository": { "type": "git", "url": "https://github.com/ql-io/ql.io" diff --git a/modules/console/test/routes/a-useritems-withDelete.ql b/modules/console/test/routes/a-useritems-withDelete.ql new file mode 100644 index 00000000..146ef953 --- /dev/null +++ b/modules/console/test/routes/a-useritems-withDelete.ql @@ -0,0 +1,13 @@ +-- Type ql script here - all keywords must be in lower case +item = select * from ebay.shopping.singleitem where itemId = '260852758792'; +profile = select * from ebay.shopping.userprofile where includeSelector = "{selector}" and userId = "260852758792"; +tradingItem = select * from ebay.trading.getitem where itemId = '260852758792'; +bidders = select * from ebay.trading.getallbidders where itemId = '260852758792'; +bestOffers = select * from ebay.trading.bestoffers where itemId = '260852758792'; +return { +"user" : "{profile}", +"item" : "{item}", +"tradingItem" : "{tradingItem}", +"bidders" : "{bidders}", +"bestOffers" : "{bestOffers}" +} via route "/del/foo/bar/{selector}?userid={userId}" using method delete; \ No newline at end of file diff --git a/modules/console/test/test-route.js b/modules/console/test/test-route.js index 48d536b2..f767ae5b 100644 --- a/modules/console/test/test-route.js +++ b/modules/console/test/test-route.js @@ -24,7 +24,7 @@ var _ = require('underscore'), url = require('url'); module.exports = { - 'check delete call' : function(test) { + 'check delete /del/foo/bar/{selector}?userid={userId}&itemid={itemId}' : function(test) { var c = new Console({ tables : __dirname + '/tables', routes : __dirname + '/routes/', @@ -71,6 +71,53 @@ module.exports = { }); }) }, + 'check delete /del/foo/bar/{selector}?userid={userId}' : function(test) { + var c = new Console({ + tables : __dirname + '/tables', + routes : __dirname + '/routes/', + config : __dirname + '/config/dev.json', + 'enable console' : false, + connection : 'close' + }); + c.app.listen(3000, function() { + var testHttpapp = express.createServer(); + testHttpapp.post('/ping/pong', function(req, res) { + var data = ''; + req.on('data', function(chunk) { + data += chunk; + }); + req.on('end', function() { + res.send(data); + }); + }); + + testHttpapp.listen(80126, function() { + var options = { + host : 'localhost', + port : 3000, + path : '/del/foo/bar/Details?userid=sallamar', + method : 'DELETE' + }; + var req = http.request(options); + req.addListener('response', function(resp) { + var data = ''; + resp.addListener('data', function(chunk) { + data += chunk; + }); + resp.addListener('end', function() { + var json = JSON.parse(data); + test.ok(json.user, 'missing user data'); + test.ok(json.user.Ack, 'missing user Ack'); + test.equal(json.user.Ack, 'Success'); + c.app.close(); + testHttpapp.close(); + test.done(); + }); + }); + req.end(); + }); + }) + }, 'check post json call' : function(test) { var c = new Console({ tables : __dirname + '/tables',