From 855ebe87a5f086262ed7ee8ff4180bbc421ed6f0 Mon Sep 17 00:00:00 2001 From: sampar Date: Tue, 15 Apr 2014 17:39:53 -0700 Subject: [PATCH] Null checks for proxy.js when extracting Session ID, default to blank --- lib/server/proxy.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/server/proxy.js b/lib/server/proxy.js index 7e04e66fb..031704d80 100644 --- a/lib/server/proxy.js +++ b/lib/server/proxy.js @@ -41,9 +41,12 @@ module.exports.doProxy = function (req, res) { logger.debug("Proxying command to " + req.device.proxyHost + ":" + req.device.proxyPort); var sessRe = new RegExp('^/wd/hub/session/([^/]+)'); - var origSessId = sessRe.exec(req.originalUrl)[1]; + var sessionRegxMatch = sessRe.exec(req.originalUrl); + // there might be no session id in the orig. req. if so, consider it to be a + // blank string + var origSessId = sessionRegxMatch ? sessionRegxMatch[1] : ''; var sessId = req.device.proxySessionId ? req.device.proxySessionId : - sessRe.exec(req.originalUrl)[1]; + origSessId; var newPath = req.originalUrl.replace(origSessId, sessId); var url = 'http://' + req.device.proxyHost + ':' + req.device.proxyPort + newPath;