Skip to content

Commit

Permalink
Merge branch 'ceesgeene-clonerequestonredirectcheck' into 8.x-1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Berdir committed Feb 1, 2016
2 parents f6abadd + 0328ba7 commit f04c284
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/EventSubscriber/RedirectRequestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ public function __construct(RedirectRepository $redirect_repository, LanguageMan
* The event to process.
*/
public function onKernelRequestCheckRedirect(GetResponseEvent $event) {
$request = $event->getRequest();
// Get a clone of the request. During inbound processing the request
// can be altered. Allowing this here can lead to unexpected behavior.
// For example the path_processor.files inbound processor provided by
// the system module alters both the path and the request; only the
// changes to the request will be propagated, while the change to the
// path will be lost.
$request = clone $event->getRequest();

if (!$this->checker->canRedirect($request)) {
return;
Expand Down
22 changes: 2 additions & 20 deletions tests/src/Unit/RedirectRequestSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Drupal\redirect\EventSubscriber\RedirectRequestSubscriber;
use Drupal\Tests\UnitTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
Expand Down Expand Up @@ -255,25 +255,7 @@ protected function getPostResponseEvent($headers = array()) {
* @return GetResponseEvent
*/
protected function getGetResponseEventStub($path_info, $query_string) {

$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
->disableOriginalConstructor()
->getMock();
$request->expects($this->any())
->method('getQueryString')
->will($this->returnValue($query_string));
$request->expects($this->any())
->method('getPathInfo')
->will($this->returnValue($path_info));
$request->expects($this->any())
->method('getScriptName')
->will($this->returnValue('index.php'));
$request->expects($this->any())
->method('isMethod')
->with('GET')
->will($this->returnValue(TRUE));

$request->attributes = new ParameterBag();
$request = Request::create($path_info . '?' . $query_string, 'GET', [], [], [], ['SCRIPT_NAME' => 'index.php']);

$http_kernel = $this->getMockBuilder('\Symfony\Component\HttpKernel\HttpKernelInterface')
->getMock();
Expand Down

0 comments on commit f04c284

Please sign in to comment.