Skip to content

Commit bfa123a

Browse files
committed
Merge branch '2.2' into 2.3
* 2.2: [Security] fixed some phpdoc Fixed PHPDoc Blocks optimized circular reference checker [HttpKernel] changed fragment URLs to be relative by default (closes #8458)
2 parents 581fb22 + eaf0064 commit bfa123a

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

Fragment/RoutableFragmentRenderer.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ public function setFragmentPath($path)
4040
* Generates a fragment URI for a given controller.
4141
*
4242
* @param ControllerReference $reference A ControllerReference instance
43-
* @param Request $request A Request instance
43+
* @param Request $request A Request instance
44+
* @param Boolean $absolute Whether to generate an absolute URL or not
4445
*
4546
* @return string A fragment URI
4647
*/
47-
protected function generateFragmentUri(ControllerReference $reference, Request $request)
48+
protected function generateFragmentUri(ControllerReference $reference, Request $request, $absolute = false)
4849
{
4950
// We need to forward the current _format and _locale values as we don't have
5051
// a proper routing pattern to do the job for us.
@@ -62,6 +63,12 @@ protected function generateFragmentUri(ControllerReference $reference, Request $
6263

6364
$reference->query['_path'] = http_build_query($reference->attributes, '', '&');
6465

65-
return $request->getUriForPath($this->fragmentPath.'?'.http_build_query($reference->query, '', '&'));
66+
$path = $this->fragmentPath.'?'.http_build_query($reference->query, '', '&');
67+
68+
if ($absolute) {
69+
return $request->getUriForPath($path);
70+
}
71+
72+
return $request->getBaseUrl().$path;
6673
}
6774
}

Tests/Fragment/EsiFragmentRendererTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testRender()
4848
$this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
4949
$this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
5050
$this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
51-
$this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
51+
$this->assertEquals('<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
5252
}
5353

5454
private function getInlineStrategy($called = false)

Tests/Fragment/HIncludeFragmentRendererTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testRenderWithControllerAndSigner()
3838
{
3939
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
4040

41-
$this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=g4b3vtCnhkZBFKrciEFwG7fucVo%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
41+
$this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=5RZ1IkwF487EaXt6buHka73CCtQ%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
4242
}
4343

4444
public function testRenderWithUri()

Tests/Fragment/RoutableFragmentRendererTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ public function testGenerateFragmentUri($uri, $controller)
2525
$this->assertEquals($uri, $this->getRenderer()->doGenerateFragmentUri($controller, Request::create('/')));
2626
}
2727

28+
/**
29+
* @dataProvider getGenerateFragmentUriData
30+
*/
31+
public function testGenerateAbsoluteFragmentUri($uri, $controller)
32+
{
33+
$this->assertEquals('http://localhost'.$uri, $this->getRenderer()->doGenerateFragmentUri($controller, Request::create('/'), true));
34+
}
35+
2836
public function getGenerateFragmentUriData()
2937
{
3038
return array(
31-
array('http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
32-
array('http://localhost/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
33-
array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
34-
array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
35-
array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
39+
array('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
40+
array('/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
41+
array('/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
42+
array('/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
43+
array('/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
3644
);
3745
}
3846

@@ -43,7 +51,7 @@ public function testGenerateFragmentUriWithARequest()
4351
$request->setLocale('fr');
4452
$controller = new ControllerReference('controller', array(), array());
4553

46-
$this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request));
54+
$this->assertEquals('/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request));
4755
}
4856

4957
private function getRenderer()
@@ -57,8 +65,8 @@ class Renderer extends RoutableFragmentRenderer
5765
public function render($uri, Request $request, array $options = array()) {}
5866
public function getName() {}
5967

60-
public function doGenerateFragmentUri(ControllerReference $reference, Request $request)
68+
public function doGenerateFragmentUri(ControllerReference $reference, Request $request, $absolute = false)
6169
{
62-
return parent::generateFragmentUri($reference, $request);
70+
return parent::generateFragmentUri($reference, $request, $absolute);
6371
}
6472
}

0 commit comments

Comments
 (0)