Remove _path from query parameters when fragment is a subrequest and request attributes are already set
Added tests for _path removal in FragmentListener
This commit is contained in:
parent
2c43532376
commit
c3744202f6
@ -58,7 +58,14 @@ class FragmentListener implements EventSubscriberInterface
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,31 @@ class FragmentListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$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);
|
||||
|
Reference in New Issue
Block a user