From 5ecf3ef5eb0e2fa0bd92cc0f80ecb7c85c3ccc68 Mon Sep 17 00:00:00 2001 From: Sven Rautenberg Date: Mon, 30 Apr 2018 10:52:19 +0200 Subject: [PATCH] Add escaping to strings read from env Symfony treats strings containing two percent signs as a variable to be replaced. Jenkins will escape slashes in branch names as "%2f", having a branch name with two slashes leads to the env variables "JOB_NAME" and "BUILD_NUMBER" to contain two percent signs, which triggers Symfony DIs variable replacement, and fails Behat execution with a ParameterNotFound exception. --- .../Driver/Selenium2Factory.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php b/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php index fcdcebaf..407694f7 100644 --- a/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php +++ b/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php @@ -62,19 +62,19 @@ public function buildDriver(array $config) if (getenv('TRAVIS_JOB_NUMBER')) { $guessedCapabilities = array( - 'tunnel-identifier' => getenv('TRAVIS_JOB_NUMBER'), - 'build' => getenv('TRAVIS_BUILD_NUMBER'), - 'tags' => array('Travis-CI', 'PHP '.phpversion()), + 'tunnel-identifier' => $this->escapeForSymfonyDi(getenv('TRAVIS_JOB_NUMBER')), + 'build' => $this->escapeForSymfonyDi(getenv('TRAVIS_BUILD_NUMBER')), + 'tags' => array('Travis-CI', $this->escapeForSymfonyDi('PHP '.phpversion())), ); } elseif (getenv('JENKINS_HOME')) { $guessedCapabilities = array( - 'tunnel-identifier' => getenv('JOB_NAME'), - 'build' => getenv('BUILD_NUMBER'), - 'tags' => array('Jenkins', 'PHP '.phpversion(), getenv('BUILD_TAG')), + 'tunnel-identifier' => $this->escapeForSymfonyDi(getenv('JOB_NAME')), + 'build' => $this->escapeForSymfonyDi(getenv('BUILD_NUMBER')), + 'tags' => array('Jenkins', $this->escapeForSymfonyDi('PHP '.phpversion()), $this->escapeForSymfonyDi(getenv('BUILD_TAG'))), ); } else { $guessedCapabilities = array( - 'tags' => array(php_uname('n'), 'PHP '.phpversion()), + 'tags' => array($this->escapeForSymfonyDi(php_uname('n')), $this->escapeForSymfonyDi('PHP '.phpversion())), ); } @@ -158,4 +158,13 @@ protected function getCapabilitiesNode() return $node; } + + /** + * @param string $getenv + * @param string + */ + private function escapeForSymfonyDi($getenv) + { + return str_replace('%', '%%', $getenv); + } }