ソースを参照

Remove support for integers with leading 0s

The additional ctype_digit logic is more complex than using filter_var()
and I don't think there are many useful scenarios for leading 0s as they
could be ambiguous with octal representations.

See discussion in #16643
Mark Story 3 年 前
コミット
6615ea8448

+ 1 - 1
src/Controller/ControllerFactory.php

@@ -268,7 +268,7 @@ class ControllerFactory implements ControllerFactoryInterface, RequestHandlerInt
             case 'float':
                 return is_numeric($argument) ? (float)$argument : null;
             case 'int':
-                return ctype_digit($argument) || filter_var($argument, FILTER_VALIDATE_INT) ? (int)$argument : null;
+                return filter_var($argument, FILTER_VALIDATE_INT) ? (int)$argument : null;
             case 'bool':
                 return $argument === '0' ? false : ($argument === '1' ? true : null);
             case 'array':

+ 2 - 2
tests/TestCase/Controller/ControllerFactoryTest.php

@@ -733,7 +733,7 @@ class ControllerFactoryTest extends TestCase
                 'plugin' => null,
                 'controller' => 'Dependencies',
                 'action' => 'requiredTyped',
-                'pass' => ['1.0', '02', '0', '8,9'],
+                'pass' => ['1.0', '2', '0', '8,9'],
             ],
         ]);
         $controller = $this->factory->create($request);
@@ -748,7 +748,7 @@ class ControllerFactoryTest extends TestCase
                 'plugin' => null,
                 'controller' => 'Dependencies',
                 'action' => 'requiredTyped',
-                'pass' => ['1.0', '02', '0', ''],
+                'pass' => ['1.0', '2', '0', ''],
             ],
         ]);
         $controller = $this->factory->create($request);