Skip to content

Commit

Permalink
Validate controller references with scope resolution operator stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteWunsch committed Oct 30, 2024
1 parent f29494d commit 640c445
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Handler/EmbeddedShortcodeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function validateControllerName(string $controllerName): void
}

$callableFragments = explode('::', $controllerName);
if (!\is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) {
if (!\is_array($callableFragments) || count($callableFragments) !== 2 || !method_exists($callableFragments[0], $callableFragments[1])) {
throw new InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.');
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/EmbeddedShortcodeHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static function provideControllerNames(): Generator
yield 'Missing method name' => [ShortcodeTestController::class];
yield 'Not existing method' => [ShortcodeTestController::class.'_notExistingMethod'];
yield 'Missing class' => ['ThisClassDoesNotExist'];
yield 'Valid reference followed by a second scope resolution operator' => [ShortcodeTestController::class.'::test::'];
}

private function processShortcodes(string $content, ?Request $request = null): string
Expand Down

0 comments on commit 640c445

Please sign in to comment.