Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 545c822

Browse files
author
Craig Menning
committed
Remove _path from query parameters when fragment is a subrequest and request attributes are already set
Added tests for _path removal in FragmentListener
1 parent 2c43532 commit 545c822

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ public function onKernelRequest(GetResponseEvent $event)
5858
{
5959
$request = $event->getRequest();
6060

61-
if ($request->attributes->has('_controller') || $this->fragmentPath !== rawurldecode($request->getPathInfo())) {
61+
if ($this->fragmentPath !== rawurldecode($request->getPathInfo())) {
62+
return;
63+
}
64+
65+
if ($request->attributes->has('_controller')) {
66+
// Is a sub-request: no need to parse _path but it should still be removed from query parameters as below.
67+
$request->query->remove('_path');
68+
6269
return;
6370
}
6471

src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ public function testWithSignature()
8989
$this->assertFalse($request->query->has('_path'));
9090
}
9191

92+
public function testRemovesPathWithControllerDefined()
93+
{
94+
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo');
95+
96+
$listener = new FragmentListener(new UriSigner('foo'));
97+
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
98+
99+
$listener->onKernelRequest($event);
100+
101+
$this->assertFalse($request->attributes->has('_path'));
102+
}
103+
104+
public function testRemovesPathWithControllerNotDefined()
105+
{
106+
$signer = new UriSigner('foo');
107+
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1'));
108+
109+
$listener = new FragmentListener($signer);
110+
$event = $this->createGetResponseEvent($request);
111+
112+
$listener->onKernelRequest($event);
113+
114+
$this->assertFalse($request->attributes->has('_path'));
115+
}
116+
92117
private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
93118
{
94119
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, $requestType);

0 commit comments

Comments
 (0)