[BUGFIX] Fix blacklist in DebuggerUtility::var_dump 58/49258/2
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 27 Jul 2016 13:57:50 +0000 (15:57 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 28 Jul 2016 22:03:16 +0000 (00:03 +0200)
Wrong usage of strpos leads to not respecting the given blacklist.
Use in_array instead to solve the problem.

Resolves: #72407
Releases: master,7.6
Change-Id: I774bb7c4c9c2bd1c32b2955368b5d9033256100b
Reviewed-on: https://review.typo3.org/49258
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/extbase/Classes/Utility/DebuggerUtility.php
typo3/sysext/extbase/Tests/Unit/Utility/DebuggerUtilityTest.php

index 7c0ae47..2e7e7d8 100644 (file)
@@ -199,9 +199,9 @@ class DebuggerUtility
     {
         $result = false;
         if ($value instanceof \ReflectionProperty) {
-            $result = (strpos(implode('|', self::$blacklistedPropertyNames), $value->getName()) > 0);
+            $result = in_array($value->getName(), self::$blacklistedPropertyNames, true);
         } elseif (is_object($value)) {
-            $result = (strpos(implode('|', self::$blacklistedClassNames), get_class($value)) > 0);
+            $result = in_array(get_class($value), self::$blacklistedClassNames, true);
         }
         return $result;
     }
index 05e76da..9df7442 100644 (file)
@@ -13,11 +13,13 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
 
 /**
  * Test case
  */
-class DebuggerUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+class DebuggerUtilityTest extends UnitTestCase
 {
     /**
      * @var \TYPO3\CMS\Extbase\Utility\DebuggerUtility
@@ -26,7 +28,7 @@ class DebuggerUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     protected function setUp()
     {
-        $this->debugger = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Utility\DebuggerUtility::class, array('dummy'));
+        $this->debugger = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Utility\DebuggerUtility::class, ['dummy']);
     }
 
     /**
@@ -73,4 +75,31 @@ class DebuggerUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $result = $this->debugger->var_dump($testObject, null, 8, true, false, true);
         $this->assertRegExp('/foo.*bar/', $result);
     }
+
+    /**
+     * @test
+     * @return void
+     */
+    public function varDumpRespectsBlacklistedProperties()
+    {
+        $testClass = new \stdClass();
+        $testClass->secretData = 'I like cucumber.';
+        $testClass->notSoSecretData = 'I like burger.';
+
+        $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, null, ['secretData']);
+        self::assertNotContains($testClass->secretData, $result);
+    }
+
+    /**
+     * @test
+     * @return void
+     */
+    public function varDumpRespectsBlacklistedClasses()
+    {
+        $testClass = new \stdClass();
+        $testClass->data = 'I like burger.';
+
+        $result = DebuggerUtility::var_dump($testClass, null, 8, true, false, true, [\stdClass::class]);
+        self::assertNotContains($testClass->data, $result);
+    }
 }