[BUGFIX] uploading extname_1.0.3 (1).zip creates extension "extname (1)" 78/21078/2
authorPhilipp Gampe <philipp.gampe@typo3.org>
Fri, 17 May 2013 15:11:17 +0000 (17:11 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sun, 26 May 2013 17:58:01 +0000 (19:58 +0200)
The function getExtensionFromZipFile fails to sanitize any output after
the version. As the function is only interested in the part before the
version which must be the extension key, remove any trailing characters.

Add a unit test to document this behavior.

Resolves: #48332
Releases: 6.2, 6.1, 6.0
Change-Id: I09b810d4bce214b6fa38e1a62200560f30d88984
Reviewed-on: https://review.typo3.org/21078
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/extensionmanager/Classes/Controller/UploadExtensionFileController.php
typo3/sysext/extensionmanager/Tests/Unit/Controller/UploadExtensionFileControllerTest.php [new file with mode: 0644]

index d715fe0..6ffb8a0 100644 (file)
@@ -154,11 +154,11 @@ class UploadExtensionFileController extends \TYPO3\CMS\Extensionmanager\Controll
         * @param string $fileName Filename (basename) of uploaded file
         * @param boolean $overwrite Overwrite existing extension if TRUE
         * @return array
+        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
         */
        protected function getExtensionFromZipFile($file, $fileName, $overwrite = FALSE) {
                        // Remove version and ending from filename to determine extension key
-               $extensionKey = preg_replace('/_(\d+)(\.|\-)(\d+)(\.|\-)(\d+)/i', '', strtolower($fileName));
-               $extensionKey = substr($extensionKey, 0, strrpos($extensionKey, '.'));
+               $extensionKey = preg_replace('/_(\d+)(\.|\-)(\d+)(\.|\-)(\d+).*/i', '', strtolower($fileName));
                if (!$overwrite && $this->installUtility->isAvailable($extensionKey)) {
                        throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Extension is already available and overwriting is disabled.', 1342864311);
                }
@@ -169,5 +169,4 @@ class UploadExtensionFileController extends \TYPO3\CMS\Extensionmanager\Controll
 
 }
 
-
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Controller/UploadExtensionFileControllerTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Controller/UploadExtensionFileControllerTest.php
new file mode 100644 (file)
index 0000000..128392b
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Controller;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2013 Philipp Gampe <philipp.gampe@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Update from TER controller test
+ *
+ */
+class UploadExtensionFileControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @return array The test data for getExtensionFromZipFileExtractsExtensionKey
+        */
+       public function getExtensionFromZipFileExtractsExtensionKeyDataProvider() {
+               return array(
+                       'simple' => array(
+                               'extension_0.0.0.zip',
+                               'extension'
+                       ),
+                       'underscore in extension name' => array(
+                               'extension_key_10.100.356.zip',
+                               'extension_key'
+                       ),
+                       'camel case file name' => array(
+                               'extensionName_1.1.1.zip',
+                               'extensionname'
+                       ),
+                       'version with dashes' => array(
+                               'extension_1-2-3.zip',
+                               'extension'
+                       ),
+                       'characters after version' => array(
+                               'extension_1-2-3(1).zip',
+                               'extension'
+                       ),
+                       'characters after version with extra space' => array(
+                               'extension_1-2-3 (1).zip',
+                               'extension'
+                       )
+               );
+       }
+       /**
+        * @test
+        * @dataProvider getExtensionFromZipFileExtractsExtensionKeyDataProvider
+        * @param string $filename The file name to test
+        * @param string $expectedKey The expected extension key
+        * @return void
+        */
+       public function getExtensionFromZipFileExtractsExtensionKey($filename, $expectedKey) {
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UploadExtensionFileController', array('dummy'));
+               $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
+               $installUtilityMock->expects($this->once())->method('install');
+               $fixture->_set('installUtility', $installUtilityMock);
+               $fileHandlingUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility');
+               $fileHandlingUtilityMock->expects($this->once())->method('unzipExtensionFromFile');
+               $fixture->_set('fileHandlingUtility', $fileHandlingUtilityMock);
+
+               $extensionDetails = $fixture->_call('getExtensionFromZipFile', '', $filename);
+               $this->assertEquals($expectedKey, $extensionDetails['extKey']);
+       }
+
+}
+
+?>
\ No newline at end of file