From d31ccee727c4ff367402bdae17f55e20fdb232b9 Mon Sep 17 00:00:00 2001 From: Isaac Murchie Date: Wed, 16 Apr 2014 12:33:20 -0700 Subject: [PATCH] Allow for different inputs to find --- lib/server/controller.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/server/controller.js b/lib/server/controller.js index fe821ddfc..530427780 100644 --- a/lib/server/controller.js +++ b/lib/server/controller.js @@ -260,9 +260,8 @@ exports.performTouch = function (req, res) { // some clients, like Python, send an object in which there is an `actions` // property that is the array of actions - // if this is not an array (having a `shift` method) try to get the - // actions from there - if (typeof gestures.shift !== 'function') { + // get the gestures from there if we don't already have an array + if (gestures && !Array.isArray(gestures)) { gestures = gestures.actions; } @@ -429,8 +428,16 @@ exports.mobileSource = function (req, res) { exports.find = function (req, res) { var strategy = "dynamic" - , selector = req.body - , all = selector && selector[0] && typeof selector[0] === "string" && selector[0].toLowerCase() === "all"; + , selector = req.body; + + // some clients send the selector as the `selector` property of an object, + // rather than the whole body. + // selector ought to be an array + if (selector && !Array.isArray(selector)) { + selector = req.body.selector; + } + + var all = selector && selector[0] && typeof selector[0] === "string" && selector[0].toLowerCase() === "all"; if (all) { req.device.findElements(strategy, selector, getResponseHandler(req, res));