Skip to content

Commit fc29e39

Browse files
author
Joan He
committed
Merge remote-tracking branch 'arcticfoxes/MAGETWO-99020' into 2.1.18-develop-pr
2 parents 90bb2a2 + fe02450 commit fc29e39

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

app/code/Magento/Config/Model/Config/Backend/Serialized.php

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,55 @@
55
*/
66
namespace Magento\Config\Model\Config\Backend;
77

8+
use Magento\Framework\Unserialize\SecureUnserializer;
9+
use Magento\Framework\App\ObjectManager;
10+
811
class Serialized extends \Magento\Framework\App\Config\Value
912
{
13+
/**
14+
* @var SecureUnserializer
15+
*/
16+
private $unserializer;
17+
18+
/**
19+
* Serialized constructor
20+
*
21+
* @param \Magento\Framework\Model\Context $context
22+
* @param \Magento\Framework\Registry $registry
23+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
24+
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
25+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
26+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
27+
* @param array $data
28+
* @param SecureUnserializer|null $unserializer
29+
*/
30+
public function __construct(
31+
\Magento\Framework\Model\Context $context,
32+
\Magento\Framework\Registry $registry,
33+
\Magento\Framework\App\Config\ScopeConfigInterface $config,
34+
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
35+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
36+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
37+
array $data = [],
38+
SecureUnserializer $unserializer = null
39+
) {
40+
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
41+
$this->unserializer = $unserializer ?: ObjectManager::getInstance()->get(SecureUnserializer::class);
42+
}
43+
1044
/**
1145
* @return void
1246
*/
1347
protected function _afterLoad()
1448
{
15-
if (!is_array($this->getValue())) {
16-
$value = $this->getValue();
17-
$this->setValue(empty($value) ? false : unserialize($value));
49+
$value = $this->getValue();
50+
if (!is_array($value)) {
51+
try {
52+
$this->setValue(empty($value) ? false : $this->unserializer->unserialize($value));
53+
} catch (\Exception $e) {
54+
$this->_logger->critical($e);
55+
$this->setValue(false);
56+
}
1857
}
1958
}
2059

@@ -23,9 +62,11 @@ protected function _afterLoad()
2362
*/
2463
public function beforeSave()
2564
{
26-
if (is_array($this->getValue())) {
27-
$this->setValue(serialize($this->getValue()));
65+
$value = $this->getValue();
66+
if (is_array($value)) {
67+
$this->setValue(serialize($value));
2868
}
29-
return parent::beforeSave();
69+
parent::beforeSave();
70+
return $this;
3071
}
3172
}

dev/tests/static/testsuite/Magento/Test/Js/_files/eslint/.eslintrc-magento

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
2,
6363
{
6464
"args": "after-used",
65-
"vars": "all"
65+
"vars": "all",
66+
"varsIgnorePattern": "config"
6667
}
6768
],
6869
"no-use-before-define": 2,

0 commit comments

Comments
 (0)