Skip to content

Commit b8ed557

Browse files
author
Joan He
committed
MAGETWO-97997: Improve pagecache block controller
1 parent 3c10b02 commit b8ed557

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

app/code/Magento/PageCache/Controller/Block.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\Framework\Serialize\Serializer\Base64Json;
1111
use Magento\Framework\Serialize\Serializer\Json;
1212

13+
/**
14+
* Page cache block controller abstract class
15+
*/
1316
abstract class Block extends \Magento\Framework\App\Action\Action
1417
{
1518
/**
@@ -55,13 +58,12 @@ public function __construct(
5558
protected function _getBlocks()
5659
{
5760
$blocks = $this->getRequest()->getParam('blocks', '');
58-
$handles = $this->getRequest()->getParam('handles', '');
61+
$handles = $this->getHandles();
5962

6063
if (!$handles || !$blocks) {
6164
return [];
6265
}
6366
$blocks = $this->jsonSerializer->unserialize($blocks);
64-
$handles = $this->base64jsonSerializer->unserialize($handles);
6567

6668
$this->_view->loadLayout($handles, true, true, false);
6769
$data = [];
@@ -76,4 +78,22 @@ protected function _getBlocks()
7678

7779
return $data;
7880
}
81+
82+
/**
83+
* Get handles
84+
*
85+
* @return array
86+
*/
87+
private function getHandles(): array
88+
{
89+
$handles = $this->getRequest()->getParam('handles', '');
90+
$handles = !$handles ? [] : $this->base64jsonSerializer->unserialize($handles);
91+
$validHandles = [];
92+
foreach ($handles as $handle) {
93+
if (!preg_match('/[@\'\*\.\\\"]/i', $handle)) {
94+
$validHandles[] = $handle;
95+
}
96+
}
97+
return $validHandles;
98+
}
7999
}

app/code/Magento/PageCache/Controller/Block/Render.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
namespace Magento\PageCache\Controller\Block;
88

9+
/**
10+
* Page cache render controller
11+
*
12+
* @deprecated
13+
*/
914
class Render extends \Magento\PageCache\Controller\Block
1015
{
1116
/**

app/code/Magento/PageCache/Test/Unit/Controller/Block/RenderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testExecuteNoParams()
111111
public function testExecute()
112112
{
113113
$blocks = ['block1', 'block2'];
114-
$handles = ['handle1', 'handle2'];
114+
$handles = ['handle1', 'handle2', "'handle'", '@hanle', '"hanle', '*hanle', '.hanle'];
115115
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
116116
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];
117117

@@ -148,7 +148,7 @@ public function testExecute()
148148
->method('getParam')
149149
->with($this->equalTo('handles'), $this->equalTo(''))
150150
->will($this->returnValue(base64_encode(json_encode($handles))));
151-
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
151+
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo(['handle1', 'handle2']));
152152
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
153153
$this->layoutMock->expects($this->at(0))
154154
->method('getBlock')

0 commit comments

Comments
 (0)