[Routing] removed trailing slash behavior on non-safe requests (refs #2626)

This commit is contained in:
Fabien Potencier 2012-07-01 19:02:05 +02:00
parent 16976be8ce
commit ed49e3be35
2 changed files with 15 additions and 1 deletions

View File

@ -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;
}

View File

@ -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();