Skip to content

Commit 25965d1

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 25965d1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ 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+
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar');
107+
108+
$listener = new FragmentListener(new UriSigner('foo'));
109+
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
110+
111+
$listener->onKernelRequest($event);
112+
113+
$this->assertFalse($request->attributes->has('_path'));
114+
}
115+
92116
private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
93117
{
94118
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, $requestType);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy