[BUGFIX] Extension installer: Handle multiple blanks 21/33321/5
authorStefan Froemken <froemken@gmail.com>
Wed, 15 Oct 2014 12:36:50 +0000 (14:36 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 6 Nov 2014 11:21:08 +0000 (12:21 +0100)
The parser of the ext_tables.sql file removes double blanks
from the input line - but only once. So if there are multiple
blanks at least double blanks remain and irritate the later
comparison about whether the field definition is different.

Resolves: #62245
Releases: master,6.2
Change-Id: I6ab4cb543f5373916388567d3d9969c6681fa8e8
Reviewed-on: http://review.typo3.org/33321
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Service/SqlSchemaMigrationService.php
typo3/sysext/install/Tests/Unit/Service/SqlSchemaMigrationServiceTest.php

index e3f37e6..4c5505b 100644 (file)
@@ -103,8 +103,8 @@ class SqlSchemaMigrationService {
                                        // Strip trailing commas
                                        $lineV = preg_replace('/,$/', '', $value);
                                        $lineV = str_replace('`', '', $lineV);
-                                       // Remove double blanks
-                                       $lineV = str_replace('  ', ' ', $lineV);
+                                       // Reduce muliple blanks and tabs except newline
+                                       $lineV = preg_replace('/\h+/', ' ', $lineV);
                                        $parts = explode(' ', $lineV, 2);
                                        // Field definition
                                        if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/', $parts[0])) {
index e7aa688..80ffc59 100644 (file)
@@ -24,22 +24,34 @@ use TYPO3\CMS\Install\Service\SqlSchemaMigrationService;
 class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
-        */
-       protected $fixture;
-
-       /**
-        * Sets up the fixture for testing
+        * @test
         */
-       public function setUp() {
-               $this->fixture = new SqlSchemaMigrationService();
+       public function getFieldDefinitionsFileContentHandlesMultipleWhitespacesInFieldDefinitions() {
+               $subject = new SqlSchemaMigrationService();
+               // Multiple whitespaces and tabs in field definition
+               $inputString = 'CREATE table aTable (' . LF . 'aFieldName   int(11)' . TAB . TAB . TAB . 'unsigned   DEFAULT \'0\'' . LF . ');';
+               $result = $subject->getFieldDefinitions_fileContent($inputString);
+               $this->assertEquals(
+                       array(
+                               'aTable' => array(
+                                       'fields' => array(
+                                               'aFieldName' => 'int(11) unsigned default \'0\'',
+                                       ),
+                                       'extra' => array(
+                                               'COLLATE' => '',
+                                       ),
+                               ),
+                       ),
+                       $result
+               );
        }
 
        /**
         * @test
         */
        public function getDatabaseExtraFindsChangedFields() {
-               $differenceArray = $this->fixture->getDatabaseExtra(
+               $subject = new SqlSchemaMigrationService();
+               $differenceArray = $subject->getDatabaseExtra(
                        array(
                                'tx_foo' => array(
                                        'fields' => array(
@@ -84,7 +96,8 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getDatabaseExtraIgnoresCaseDifference() {
-               $differenceArray = $this->fixture->getDatabaseExtra(
+               $subject = new SqlSchemaMigrationService();
+               $differenceArray = $subject->getDatabaseExtra(
                        array(
                                'tx_foo' => array(
                                        'fields' => array(
@@ -116,7 +129,8 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getDatabaseExtraDoesNotLowercaseReservedWordsForTheComparison() {
-               $differenceArray = $this->fixture->getDatabaseExtra(
+               $subject = new SqlSchemaMigrationService();
+               $differenceArray = $subject->getDatabaseExtra(
                        array(
                                'tx_foo' => array(
                                        'fields' => array(