[BUGFIX] Improve check in t3lib_div::makeInstance
authorBjoern Pedersen <bjoern.pedersen@frm2.tum.de>
Thu, 21 Jul 2011 08:14:57 +0000 (10:14 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sun, 24 Jul 2011 16:34:21 +0000 (18:34 +0200)
The strict string comparison is not enough to catch
all wrong arguments and throw a correct error.

Change-Id: Id7911229f90d1aa0f6ce5830a434bceb4ab61da5
Resolves: #25047
Releases: 4.6
Reviewed-on: http://review.typo3.org/3446
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
t3lib/class.t3lib_div.php
tests/t3lib/class.t3lib_divTest.php

index 7ebbae8..f557d4c 100644 (file)
@@ -4679,8 +4679,8 @@ final class t3lib_div {
         * @return object the created instance
         */
        public static function makeInstance($className) {
-               if ($className === '') {
-                       throw new InvalidArgumentException('$classname must not be empty.', 1288965219);
+               if (!is_string($className) || empty($className)) {
+                       throw new InvalidArgumentException('$className must be a non empty string.', 1288965219);
                }
 
                        // Determine final class name which must be instantiated, this takes XCLASS handling
@@ -5567,4 +5567,4 @@ final class t3lib_div {
        }
 }
 
-?>
+?>
\ No newline at end of file
index e87ee2a..5e576c3 100644 (file)
@@ -691,14 +691,14 @@ class t3lib_divTest extends tx_phpunit_testcase {
         * @dataProvider intInRangeForcesIntegerIntoDefaultBoundariesDataProvider
         */
        public function intInRangeForcesIntegerIntoDefaultBoundaries($expected, $value) {
-                $this->assertEquals($expected, t3lib_div::intInRange($value, 0));
+               $this->assertEquals($expected, t3lib_div::intInRange($value, 0));
        }
 
        /**
         * @test
         */
        public function intInRangeSetsDefaultValueIfZeroValueIsGiven() {
-                $this->assertEquals(42, t3lib_div::intInRange('', 0, 2000000000, 42));
+               $this->assertEquals(42, t3lib_div::intInRange('', 0, 2000000000, 42));
        }
 
        //////////////////////////////////
@@ -2805,7 +2805,6 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
        /**
         * @test
-        *
         * @expectedException InvalidArgumentException
         */
        public function makeInstanceWithEmptyClassNameThrowsException() {
@@ -2814,6 +2813,38 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
        /**
         * @test
+        * @expectedException InvalidArgumentException
+        */
+       public function makeInstanceWithNullClassNameThrowsException() {
+               t3lib_div::makeInstance(NULL);
+       }
+
+       /**
+        * @test
+        * @expectedException InvalidArgumentException
+        */
+       public function makeInstanceWithZeroStringClassNameThrowsException() {
+               t3lib_div::makeInstance(0);
+       }
+
+       /**
+        * @test
+        * @expectedException InvalidArgumentException
+        */
+       public function makeInstanceWithEmptyArrayThrowsException() {
+               t3lib_div::makeInstance(array());
+       }
+
+       /**
+        * @test
+        * @expectedException InvalidArgumentException
+        */
+       public function makeInstanceWithNonEmptyArrayThrowsException() {
+               t3lib_div::makeInstance(array('foo'));
+       }
+
+       /**
+        * @test
         */
        public function makeInstanceReturnsClassInstance() {
                $className = get_class($this->getMock('foo'));
@@ -3197,4 +3228,4 @@ class t3lib_divTest extends tx_phpunit_testcase {
                );
        }
 }
-?>
+?>
\ No newline at end of file