Verified Commit 4ca1eee3 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3628789 CallableResolver exception doesn't properly handle a bad array definition

By: joachim
By: burcu.sogut@drupart.com.tr
By: nisha_j
By: nicxvan
(cherry picked from commit 59d522ff)
parent 325c5b58
Loading
Loading
Loading
Loading
Loading
+3 −1
Changes for core/lib/Drupal/Core/Utility/CallableResolver.php: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -66,7 +66,9 @@ public function getCallableFromDefinition(callable|array|string $definition): ca
    }

    if (is_array($definition)) {
      throw new \InvalidArgumentException(sprintf('The callable definition provided "[%s]" is not a valid callable.', implode(",", $definition)));
      // The definition can contain an object, for example [$object, 'method'].
      $parts = array_map(static fn ($part) => is_scalar($part) ? (string) $part : get_debug_type($part), $definition);
      throw new \InvalidArgumentException(sprintf('The callable definition provided "[%s]" is not a valid callable.', implode(",", $parts)));
    }

    if (!is_string($definition)) {
+5
Changes for core/tests/Drupal/Tests/Core/Utility/CallableResolverTest.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -137,6 +137,11 @@ public static function callableResolverExceptionHandlingTestCases(): array {
        \InvalidArgumentException::class,
        'The callable definition provided "[stdClass,method_not_exists]" is not a valid callable.',
      ],
      'Missing method on object, array notation' => [
        [new \stdClass(), 'method_not_exists'],
        \InvalidArgumentException::class,
        'The callable definition provided "[stdClass,method_not_exists]" is not a valid callable.',
      ],
      'Missing method on class, static notation' => [
        \stdClass::class . '::method_not_exists',
        \InvalidArgumentException::class,