From 296f40a7a68aa8f3768e53d7d63dc3559d28bdef Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Thu, 15 Dec 2016 21:02:22 +0100 Subject: [PATCH] [Security] Fix error when calling HttpUtils::generateUri() --- src/Symfony/Component/Security/Http/HttpUtils.php | 4 ++++ .../Component/Security/Http/Tests/HttpUtilsTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/Security/Http/HttpUtils.php b/src/Symfony/Component/Security/Http/HttpUtils.php index ed737a2f61695..c56ef20773925 100644 --- a/src/Symfony/Component/Security/Http/HttpUtils.php +++ b/src/Symfony/Component/Security/Http/HttpUtils.php @@ -135,6 +135,10 @@ public function generateUri($request, $path) return $path; } + if (!$request instanceof Request) { + throw new \InvalidArgumentException(sprintf('The first argument of %s() must be an instance of %s.', __METHOD__, Request::class)); + } + if ('/' === $path[0]) { return $request->getUriForPath($path); } diff --git a/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php b/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php index 45a0281591b95..431d186b96542 100644 --- a/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php +++ b/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php @@ -238,6 +238,16 @@ public function testGenerateUriRemovesQueryString() $this->assertEquals('/foo/bar', $utils->generateUri(new Request(), 'route_name')); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The first argument of Symfony\Component\Security\Http\HttpUtils::generateUri() must be an instance of Symfony\Component\HttpFoundation\Request. + */ + public function testGenerateUriThrowsExceptionIfNotAnInstanceOfRequest() + { + $utils = new HttpUtils(); + $utils->generateUri(null, '/foo/bar'); + } + /** * @expectedException \LogicException * @expectedExceptionMessage You must provide a UrlGeneratorInterface instance to be able to use routes.