From 3fe596be635b19fb80541b90645c8a1a1f3022d7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 18 Jun 2014 12:57:11 +1200 Subject: [PATCH] Fix quoting in getRegionObj() Based on work by @jeffreyguo. See https://github.com/silverstripe-labs/silverstripe-behat-extension/pull/53/commits --- .../Context/SilverStripeContext.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index d2c701f..a21cf83 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -131,22 +131,33 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex /** * Returns MinkElement based off region defined in .yml file. * Also supports direct CSS selectors and regions identified by a "data-title" attribute. - * + * When using the "data-title" attribute, ensure not to include double quotes. + * * @param String $region Region name or CSS selector * @return MinkElement|null */ public function getRegionObj($region) { - // Try to find regions directly by CSS selector - $regionObj = $this->getSession()->getPage()->find('css', - $this->getSession()->getSelectorsHandler()->xpathLiteral($region)); + // Try to find regions directly by CSS selector. + $regionObj = $this->getSession()->getPage()->find( + 'css', + // Escape CSS selector + (false !== strpos($region, "'")) ? str_replace("'", "\'", $region) : $region + ); if($regionObj) { return $regionObj; } - // Fall back to region identified by data-tilte - $regionObj = $this->getSession()->getPage()->find('css', '[data-title="' . $region . '"]'); - if($regionObj) { - return $regionObj; + // Fall back to region identified by data-title. + // Only apply if no double quotes exist in search string, + // which would break the CSS selector. + if(false === strpos($region, '"')) { + $regionObj = $this->getSession()->getPage()->find( + 'css', + '[data-title="' . $region . '"]' + ); + if($regionObj) { + return $regionObj; + } } // Look for named region