From ed49e3be35b64fabc9dd643720aed96b0d9d2f33 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 1 Jul 2012 19:02:05 +0200 Subject: [PATCH] [Routing] removed trailing slash behavior on non-safe requests (refs #2626) --- .../Routing/Matcher/RedirectableUrlMatcher.php | 2 +- .../Tests/Matcher/RedirectableUrlMatcherTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php index 8826c59854..51e80057cd 100644 --- a/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php @@ -29,7 +29,7 @@ abstract class RedirectableUrlMatcher extends UrlMatcher implements Redirectable try { $parameters = parent::match($pathinfo); } catch (ResourceNotFoundException $e) { - if ('/' === substr($pathinfo, -1)) { + if ('/' === substr($pathinfo, -1) || !in_array($this->context->getMethod(), array('HEAD', 'GET'))) { throw $e; } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php index 43c958b150..b8ab2647ff 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php @@ -27,6 +27,20 @@ class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase $matcher->match('/foo'); } + /** + * @expectedException Symfony\Component\Routing\Exception\ResourceNotFoundException + */ + public function testRedirectWhenNoSlashForNonSafeMethod() + { + $coll = new RouteCollection(); + $coll->add('foo', new Route('/foo/')); + + $context = new RequestContext(); + $context->setMethod('POST'); + $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, $context)); + $matcher->match('/foo'); + } + public function testSchemeRedirect() { $coll = new RouteCollection();