Commit 52f02da5 authored by alexpott's avatar alexpott
Browse files

Issue #2265939 by tim.plunkett, dawehner, effulgentsia: Fixed [sechole]...

Issue #2265939 by tim.plunkett, dawehner, effulgentsia: Fixed [sechole] AccessManager::checkNamedRoute() leaks attributes from current request.
parent 85af8677
......@@ -12,6 +12,7 @@
use Drupal\Core\Routing\RequestHelper;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
......@@ -185,11 +186,16 @@ public function checkNamedRoute($route_name, array $parameters = array(), Accoun
try {
$route = $this->routeProvider->getRouteByName($route_name, $parameters);
if (empty($route_request)) {
// Create a request and copy the account from the current request.
$defaults = $parameters + $route->getDefaults();
$route_request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), $this->urlGenerator->generate($route_name, $defaults));
$defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
$route_request->attributes->add($this->paramConverterManager->convert($defaults, $route_request));
// Create a cloned request with fresh attributes.
$route_request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), $this->urlGenerator->generate($route_name, $parameters));
$route_request->attributes->replace(array());
// Populate $route_request->attributes with both raw and converted
// parameters.
$parameters += $route->getDefaults();
$route_request->attributes->set('_raw_variables', new ParameterBag($parameters));
$parameters[RouteObjectInterface::ROUTE_OBJECT] = $route;
$route_request->attributes->add($this->paramConverterManager->convert($parameters, $route_request));
}
return $this->check($route, $route_request, $account);
}
......
......@@ -299,6 +299,17 @@ function testViewModeCustom() {
$this->assertNodeViewNoText($node, 'rss', $value, "The previous settings are kept when 'rss' mode is specialized again.");
}
/**
* Tests the local tasks are displayed correctly for view modes.
*/
public function testViewModeLocalTasks() {
$manage_display = 'admin/structure/types/manage/' . $this->type . '/display';
$this->drupalGet($manage_display);
$this->assertNoLink('Full content');
$this->drupalGet($manage_display . '/teaser');
$this->assertNoLink('Full content');
}
/**
* Tests that field instances with no explicit display settings do not break.
*/
......
......@@ -421,11 +421,13 @@ public function testCheckNamedRoute() {
$this->paramConverter->expects($this->at(0))
->method('convert')
->with(array(RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_2')))
->will($this->returnValue(array()));
$this->paramConverter->expects($this->at(1))
->method('convert')
->will($this->returnValue(array()));
->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_4')))
->will($this->returnValue(array('value' => 'example')));
// Tests the access with routes with parameters without given request.
$this->assertTrue($this->accessManager->checkNamedRoute('test_route_2', array(), $this->account));
......@@ -459,6 +461,7 @@ public function testCheckNamedRouteWithUpcastedValues() {
$this->paramConverter = $this->getMock('Drupal\Core\ParamConverter\ParamConverterManagerInterface');
$this->paramConverter->expects($this->at(0))
->method('convert')
->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $route))
->will($this->returnValue(array('value' => 'upcasted_value')));
$this->argumentsResolver->expects($this->atLeastOnce())
......@@ -512,7 +515,7 @@ public function testCheckNamedRouteWithDefaultValue() {
$this->urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
$this->urlGenerator->expects($this->any())
->method('generate')
->with('test_route_1', array('value' => 'example'))
->with('test_route_1', array())
->will($this->returnValueMap($map));
$this->paramConverter = $this->getMock('Drupal\Core\ParamConverter\ParamConverterManagerInterface');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment