Skip to content

Commit

Permalink
Remove _path from query parameters when fragment is a subrequest and …
Browse files Browse the repository at this point in the history
…request attributes are already set

Added tests for _path removal in FragmentListener
  • Loading branch information
Craig Menning committed Mar 2, 2016
1 parent 2c43532 commit c374420
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Expand Up @@ -58,7 +58,14 @@ public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();

if ($request->attributes->has('_controller') || $this->fragmentPath !== rawurldecode($request->getPathInfo())) {
if ($this->fragmentPath !== rawurldecode($request->getPathInfo())) {
return;
}

if ($request->attributes->has('_controller')) {
// Is a sub-request: no need to parse _path but it should still be removed from query parameters as below.
$request->query->remove('_path');

return;
}

Expand Down
Expand Up @@ -89,6 +89,31 @@ public function testWithSignature()
$this->assertFalse($request->query->has('_path'));
}

public function testRemovesPathWithControllerDefined()
{
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo');

$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);

$listener->onKernelRequest($event);

$this->assertFalse($request->query->has('_path'));
}

public function testRemovesPathWithControllerNotDefined()
{
$signer = new UriSigner('foo');
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1'));

$listener = new FragmentListener($signer);
$event = $this->createGetResponseEvent($request);

$listener->onKernelRequest($event);

$this->assertFalse($request->query->has('_path'));
}

private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
{
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, $requestType);
Expand Down

0 comments on commit c374420

Please sign in to comment.