Browse Source

Fix conversion of empty string to empty array.

Fixes #16306
ADmad 4 years ago
parent
commit
4b643ba47e

+ 1 - 1
src/Controller/ControllerFactory.php

@@ -273,7 +273,7 @@ class ControllerFactory implements ControllerFactoryInterface, RequestHandlerInt
             case 'bool':
                 return $argument === '0' ? false : ($argument === '1' ? true : null);
             case 'array':
-                return explode(',', $argument);
+                return $argument === '' ? [] : explode(',', $argument);
         }
 
         return null;

+ 17 - 0
tests/TestCase/Controller/ControllerFactoryTest.php

@@ -723,6 +723,23 @@ class ControllerFactoryTest extends TestCase
 
         $this->assertNotNull($data);
         $this->assertSame(['one' => 1.0, 'two' => 2, 'three' => false, 'four' => ['8', '9']], $data);
+
+        $request = new ServerRequest([
+            'url' => 'test_plugin_three/dependencies/requiredTyped',
+            'params' => [
+                'plugin' => null,
+                'controller' => 'Dependencies',
+                'action' => 'requiredTyped',
+                'pass' => ['1.0', '02', '0', ''],
+            ],
+        ]);
+        $controller = $this->factory->create($request);
+
+        $result = $this->factory->invoke($controller);
+        $data = json_decode((string)$result->getBody(), true);
+
+        $this->assertNotNull($data);
+        $this->assertSame(['one' => 1.0, 'two' => 2, 'three' => false, 'four' => []], $data);
     }
 
     /**