[BUGFIX] Respect newlines in ['SYS']['binSetup'] 72/37672/5
authorNicole Cordes <typo3@cordes.co>
Mon, 9 Mar 2015 15:56:39 +0000 (16:56 +0100)
committerNicole Cordes <typo3@cordes.co>
Mon, 9 Mar 2015 20:34:51 +0000 (21:34 +0100)
If you separate the list of programs by new line (as suggested in the
Install Tool description), the programs aren't found.
The problem is that the newline is saved as string component by
the Install Tool. Therefore the new line separator (LF) has to
be replaced before splitting the value.

Releases: master, 6.2
Resolves: #65624
Change-Id: I39d8634265bf69d58ad4af3fd2eac913a14a3ef5
Reviewed-on: http://review.typo3.org/37672
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Classes/Utility/CommandUtility.php
typo3/sysext/core/Tests/Unit/Utility/CommandUtilityTest.php [new file with mode: 0644]

index ccdcea1..cfd3407 100644 (file)
@@ -350,9 +350,13 @@ class CommandUtility {
                $cmdArr = array();
 
                if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']) {
-                       $pathSetup = preg_split('/[\n,]+/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']);
+                       $binSetup = str_replace(array('\'.chr(10).\'', '\' . LF . \''), LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup']);
+                       $pathSetup = preg_split('/[\n,]+/', $binSetup);
                        foreach ($pathSetup as $val) {
-                               list($cmd, $cmdPath) = GeneralUtility::trimExplode('=', $val, TRUE);
+                               if (trim($val) === '') {
+                                       continue;
+                               }
+                               list($cmd, $cmdPath) = GeneralUtility::trimExplode('=', $val, TRUE, 2);
                                $cmdArr[$cmd]['app'] = basename($cmdPath);
                                $cmdArr[$cmd]['path'] = dirname($cmdPath) . '/';
                                $cmdArr[$cmd]['valid'] = TRUE;
diff --git a/typo3/sysext/core/Tests/Unit/Utility/CommandUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/CommandUtilityTest.php
new file mode 100644 (file)
index 0000000..6ccdf63
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Utility;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+use TYPO3\CMS\Core\Utility\CommandUtility;
+
+/**
+ * Test case for class \TYPO3\CMS\Core\Utility\CommandUtility
+ */
+class CommandUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * Data provider for getConfiguredApps
+        *
+        * @return array
+        */
+       public function getConfiguredAppsDataProvider() {
+               $defaultExpected = array(
+                       'perl' => array(
+                               'app' => 'perl',
+                               'path' => '/usr/bin/',
+                               'valid' => TRUE
+                       ),
+                       'unzip' => array(
+                               'app' => 'unzip',
+                               'path' => '/usr/local/bin/',
+                               'valid' => TRUE
+                       ),
+               );
+               return array(
+                       'returns empty array for empty string' => array(
+                               '',
+                               array()
+                       ),
+                       'separated by comma' => array(
+                               'perl=/usr/bin/perl,unzip=/usr/local/bin/unzip',
+                               $defaultExpected
+                       ),
+                       'separated by new line' => array(
+                               'perl=/usr/bin/perl ' . LF . ' unzip=/usr/local/bin/unzip',
+                               $defaultExpected
+                       ),
+                       'separated by new line with spaces' => array(
+                               'perl = /usr/bin/perl ' . LF . ' unzip = /usr/local/bin/unzip',
+                               $defaultExpected
+                       ),
+                       'separated by new line with spaces and empty rows' => array(
+                               LF . 'perl = /usr/bin/perl ' . LF . LF . ' unzip = /usr/local/bin/unzip' . LF,
+                               $defaultExpected
+                       ),
+                       'separated by char(10)' => array(
+                               'perl=/usr/bin/perl' . '\'.chr(10).\'' . 'unzip=/usr/local/bin/unzip',
+                               $defaultExpected
+                       ),
+                       'separated by LF as string' => array(
+                               'perl=/usr/bin/perl' . '\' . LF . \'' . 'unzip=/usr/local/bin/unzip',
+                               $defaultExpected
+                       )
+               );
+       }
+
+       /**
+        * @dataProvider getConfiguredAppsDataProvider
+        * @param array $globalsBinSetup
+        * @param array $expected
+        * @test
+        */
+       public function getConfiguredApps($globalsBinSetup, $expected) {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['binSetup'] = $globalsBinSetup;
+               $commandUtilityMock = $this->getAccessibleMock(CommandUtility::class, array('dummy'));
+               $result = $commandUtilityMock->_call('getConfiguredApps');
+               $this->assertSame($expected, $result);
+       }
+
+}