Fixed bug #16795: t3lib_div::unQuoteFilenames fails to detect quotes properly
authorJigal van Hemert <jigal@xs4all.nl>
Tue, 21 Dec 2010 13:08:05 +0000 (13:08 +0000)
committerJigal van Hemert <jigal@xs4all.nl>
Tue, 21 Dec 2010 13:08:05 +0000 (13:08 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9864 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
tests/t3lib/t3lib_divTest.php

index b61e4bb..ece27f9 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-12-21  Jigal van Hemert <jigal@xs4all.nl>
+
+       * Fixed bug #16795: t3lib_div::unQuoteFilenames fails to detect quotes properly (Thanks to Joerg Wagner, Steffen Ritter, Steffen Gebert, and others)
+
 2010-12-20  Tolleiv Nietsch  <typo3@tolleiv.de>
 
        * Fixed bug #16134: TYPO3 doesn't always fix permissions for new files
index ac1eda5..1401e66 100644 (file)
@@ -6254,14 +6254,13 @@ final class t3lib_div {
                        if ($quoteActive > -1) {
                                $paramsArr[$quoteActive] .= ' ' . $v;
                                unset($paramsArr[$k]);
-                               if (preg_match('/"$/', $v)) {
+                               if (substr($v, -1) === $paramsArr[$quoteActive][0]) {
                                        $quoteActive = -1;
                                }
-
                        } elseif (!trim($v)) {
                                unset($paramsArr[$k]); // Remove empty elements
 
-                       } elseif (preg_match('/^"/', $v)) {
+                       } elseif (preg_match('/^(["\'])/', $v) && substr($v, -1) !== $v[0]) {
                                $quoteActive = $k;
                        }
                }
@@ -6269,6 +6268,8 @@ final class t3lib_div {
                if ($unQuote) {
                        foreach ($paramsArr as $key => &$val) {
                                $val = preg_replace('/(^"|"$)/', '', $val);
+                               $val = preg_replace('/(^\'|\'$)/', '', $val);
+
                        }
                }
                        // return reindexed array
index 32fa165..9a3aae7 100644 (file)
@@ -1865,6 +1865,176 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertTrue($directoryCreated);
        }
 
+       /**
+        * Data provider for ImageMagick shell commands
+        * @see explodeAndUnquoteImageMagickCommands
+        */
+       public function imageMagickCommandsDataProvider() {
+               return array(
+                       // Some theoretical tests first
+                       array(
+                               'aa bb "cc" "dd"',
+                               array('aa', 'bb', '"cc"', '"dd"'),
+                               array('aa', 'bb', 'cc', 'dd'),
+                       ),
+                       array(
+                               'aa bb "cc dd"',
+                               array('aa', 'bb', '"cc dd"'),
+                               array('aa', 'bb', 'cc dd'),
+                       ),
+                       array(
+                               '\'aa bb\' "cc dd"',
+                               array('\'aa bb\'', '"cc dd"'),
+                               array('aa bb', 'cc dd'),
+                       ),
+                       array(
+                               '\'aa bb\' cc "dd"',
+                               array('\'aa bb\'', 'cc', '"dd"'),
+                               array('aa bb', 'cc', 'dd'),
+                       ),
+                       // Now test against some real world examples
+                       array(
+                               '/opt/local/bin/gm.exe convert +profile \'*\' -geometry 170x136!  -negate "C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
+                               array(
+                                       '/opt/local/bin/gm.exe',
+                                       'convert',
+                                       '+profile',
+                                       '\'*\'',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
+                                       '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
+                               ),
+                               array(
+                                       '/opt/local/bin/gm.exe',
+                                       'convert',
+                                       '+profile',
+                                       '*',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       'C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]',
+                                       'C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif'
+                               ),
+                       ),
+                       array(
+                               'C:/opt/local/bin/gm.exe convert +profile \'*\' -geometry 170x136!  -negate "C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
+                               array(
+                                       'C:/opt/local/bin/gm.exe',
+                                       'convert',
+                                       '+profile',
+                                       '\'*\'',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '"C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
+                                       '"C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
+                               ),
+                               array(
+                                       'C:/opt/local/bin/gm.exe',
+                                       'convert',
+                                       '+profile',
+                                       '*',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       'C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]',
+                                       'C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif'
+                               ),
+                       ),
+                       array(
+                               '/usr/bin/gm convert +profile \'*\' -geometry 170x136!  -negate "/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
+                               array(
+                                       '/usr/bin/gm',
+                                       'convert',
+                                       '+profile',
+                                       '\'*\'',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '"/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
+                                       '"/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
+                               ),
+                               array(
+                                       '/usr/bin/gm',
+                                       'convert',
+                                       '+profile',
+                                       '*',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]',
+                                       '/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif'
+                               ),
+                       ),
+                       array(
+                               '/usr/bin/gm convert +profile \'*\' -geometry 170x136!  -negate "/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"',
+                               array(
+                                       '/usr/bin/gm',
+                                       'convert',
+                                       '+profile',
+                                       '\'*\'',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '"/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"',
+                                       '"/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"'
+                               ),
+                               array(
+                                       '/usr/bin/gm',
+                                       'convert',
+                                       '+profile',
+                                       '*',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]',
+                                       '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif'
+                               ),
+                       ),
+                       array(
+                               '/usr/bin/gm convert +profile \'*\' -geometry 170x136!  -negate \'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\' \'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\'',
+                               array(
+                                       '/usr/bin/gm',
+                                       'convert',
+                                       '+profile',
+                                       '\'*\'',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '\'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\'',
+                                       '\'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\''
+                               ),
+                               array(
+                                       '/usr/bin/gm',
+                                       'convert',
+                                       '+profile',
+                                       '*',
+                                       '-geometry',
+                                       '170x136!',
+                                       '-negate',
+                                       '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]',
+                                       '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif'
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * Tests if the commands are exploded and unquoted correctly
+        *
+        * @dataProvider        imageMagickCommandsDataProvider
+        * @test
+        */
+       public function explodeAndUnquoteImageMagickCommands($source, $expectedQuoted, $expectedUnquoted) {
+               $actualQuoted   = t3lib_div::unQuoteFilenames($source);
+               $acutalUnquoted = t3lib_div::unQuoteFilenames($source, TRUE);
+
+               $this->assertEquals($expectedQuoted, $actualQuoted, 'The exploded command does not match the expected');
+               $this->assertEquals($expectedUnquoted, $acutalUnquoted, 'The exploded and unquoted command does not match the expected');
+       }
+
 
        ///////////////////////////////
        // Tests concerning split_fileref