Issue #3491543 by mfb: symfony/http-foundation Follow up issue for isAdminPath validator

merge-requests/1473/merge
Lee Rowlands 2024-12-19 10:06:52 +10:00
parent 97cb575e36
commit c981ed1ca1
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
3 changed files with 20 additions and 2 deletions

View File

@ -7,8 +7,10 @@ use Drupal\Core\Access\AccessResultReasonInterface;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
use Symfony\Component\Routing\RouterInterface;
@ -138,7 +140,13 @@ class AccessAwareRouter implements AccessAwareRouterInterface {
* Thrown when access checking failed.
*/
public function match($pathinfo): array {
return $this->matchRequest(Request::create($pathinfo));
try {
$request = Request::create($pathinfo);
}
catch (BadRequestException $e) {
throw new ResourceNotFoundException($e->getMessage(), $e->getCode(), $e);
}
return $this->matchRequest($request);
}
}

View File

@ -3,6 +3,7 @@
namespace Drupal\Core\Routing;
use Drupal\Core\Path\CurrentPathStack;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@ -98,7 +99,12 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
* {@inheritdoc}
*/
public function match($pathinfo): array {
$request = Request::create($pathinfo);
try {
$request = Request::create($pathinfo);
}
catch (BadRequestException $e) {
throw new ResourceNotFoundException($e->getMessage(), $e->getCode(), $e);
}
return $this->matchRequest($request);
}

View File

@ -12,6 +12,7 @@ use Drupal\Core\Routing\Router;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@ -59,6 +60,9 @@ class RouterTest extends UnitTestCase {
$result = $router->match('/user/login');
$this->assertEquals('user_login', $result['_route']);
$this->expectException(ResourceNotFoundException::class);
$router->match('/user/login ');
}
}