Skip to content

Commit c7abe67

Browse files
Merge pull request #8651 from magento-cia/cia-2.4.7-beta3-develop-bugfix-11302023
Cia 2.4.7 beta3 develop bugfix 11302023
2 parents 3950014 + c1fb2ec commit c7abe67

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ class Filter extends Template
8181
*/
8282
protected $_modifiers = ['nl2br' => ''];
8383

84-
/**
85-
* @var string
86-
*/
87-
private const CACHE_KEY_PREFIX = "EMAIL_FILTER_";
88-
8984
/**
9085
* @var bool
9186
*/
@@ -414,10 +409,6 @@ public function blockDirective($construction)
414409
$skipParams = ['class', 'id', 'output'];
415410
$blockParameters = $this->getParameters($construction[2]);
416411

417-
if (isset($blockParameters['cache_key'])) {
418-
$blockParameters['cache_key'] = self::CACHE_KEY_PREFIX . $blockParameters['cache_key'];
419-
}
420-
421412
$block = null;
422413

423414
if (isset($blockParameters['class'])) {

dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class AbstractBlockTest extends \PHPUnit\Framework\TestCase
2626
*/
2727
protected $_layout = null;
2828

29+
/**
30+
* @var array
31+
*/
2932
protected static $_mocks = [];
3033

3134
/**
@@ -573,7 +576,7 @@ public function testGetCacheKey()
573576
$this->assertNotEquals($name, $key);
574577

575578
$block->setCacheKey('key');
576-
$this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . 'key', $block->getCacheKey());
579+
$this->assertEquals(AbstractBlock::CUSTOM_CACHE_KEY_PREFIX . 'key', $block->getCacheKey());
577580
}
578581

579582
/**

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Cache\LockGuardedCacheLoader;
1313
use Magento\Framework\Config\ConfigOptionsListConstants;
1414
use Magento\Framework\DataObject\IdentityInterface;
15+
use Magento\Framework\Exception\RuntimeException;
1516

1617
/**
1718
* Base class for all blocks.
@@ -41,6 +42,11 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl
4142
*/
4243
public const CACHE_KEY_PREFIX = 'BLOCK_';
4344

45+
/**
46+
* Prefix for custom cache key of block
47+
*/
48+
public const CUSTOM_CACHE_KEY_PREFIX = 'CUSTOM_BLOCK_';
49+
4450
/**
4551
* @var \Magento\Framework\View\DesignInterface
4652
*/
@@ -1038,11 +1044,16 @@ public function getCacheKeyInfo()
10381044
* Get Key for caching block content
10391045
*
10401046
* @return string
1047+
* @throws RuntimeException
10411048
*/
10421049
public function getCacheKey()
10431050
{
10441051
if ($this->hasData('cache_key')) {
1045-
return static::CACHE_KEY_PREFIX . $this->getData('cache_key');
1052+
if (preg_match('/[^a-z0-9\-\_]/i', $this->getData('cache_key'))) {
1053+
throw new RuntimeException(__('Please enter cache key with only alphanumeric or hash string.'));
1054+
}
1055+
1056+
return static::CUSTOM_CACHE_KEY_PREFIX . $this->getData('cache_key');
10461057
}
10471058

10481059
/**

lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Config\View;
1616
use Magento\Framework\Escaper;
1717
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
18+
use Magento\Framework\Exception\RuntimeException;
1819
use Magento\Framework\ObjectManagerInterface;
1920
use Magento\Framework\Session\SessionManagerInterface;
2021
use Magento\Framework\Session\SidResolverInterface;
@@ -239,7 +240,21 @@ public function testGetCacheKey()
239240
{
240241
$cacheKey = 'testKey';
241242
$this->block->setData('cache_key', $cacheKey);
242-
$this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey());
243+
$this->assertEquals(AbstractBlock::CUSTOM_CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey());
244+
}
245+
246+
/**
247+
* Test for invalid cacheKey name
248+
* @return void
249+
* @throws RuntimeException
250+
*/
251+
public function testGetCacheKeyFail(): void
252+
{
253+
$cacheKey = "test&''Key";
254+
$this->block->setData('cache_key', $cacheKey);
255+
$this->expectException(RuntimeException::class);
256+
$this->expectExceptionMessage((string)__('Please enter cache key with only alphanumeric or hash string.'));
257+
$this->block->getCacheKey();
243258
}
244259

245260
/**

0 commit comments

Comments
 (0)