core/lib/Drupal/Core/Routing/MethodFilter.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/Routing/MethodFilter.php b/core/lib/Drupal/Core/Routing/MethodFilter.php index 6d3c2e0..80812d4 100644 --- a/core/lib/Drupal/Core/Routing/MethodFilter.php +++ b/core/lib/Drupal/Core/Routing/MethodFilter.php @@ -27,8 +27,15 @@ public function filter(RouteCollection $collection, Request $request) { foreach ($collection as $name => $route) { $supported_methods = $route->getMethods(); - $all_supported_methods = array_merge($supported_methods, $all_supported_methods); - if (!in_array($method, $supported_methods)) { + + // A route not restricted to specific methods allows any method. If this + // is the case, we'll also have at least one route left in the collection, + // hence we don't need to calculate the set of all supported methods. + if (empty($supported_methods)) { + continue; + } + elseif (!in_array($method, $supported_methods)) { + $all_supported_methods = array_merge($supported_methods, $all_supported_methods); $collection->remove($name); } }