Skip to content

Commit 93b0de1

Browse files
committed
Merge remote-tracking branch 'origin/MC-17065' into borg-security-2.3
2 parents a6f4b91 + b573a7a commit 93b0de1

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class InlineEdit extends \Magento\Backend\App\Action implements HttpPostActionIn
7070
*/
7171
private $addressRegistry;
7272

73+
/**
74+
* @var \Magento\Framework\Escaper
75+
*/
76+
private $escaper;
77+
7378
/**
7479
* @param Action\Context $context
7580
* @param CustomerRepositoryInterface $customerRepository
@@ -78,6 +83,7 @@ class InlineEdit extends \Magento\Backend\App\Action implements HttpPostActionIn
7883
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
7984
* @param \Psr\Log\LoggerInterface $logger
8085
* @param AddressRegistry|null $addressRegistry
86+
* @param \Magento\Framework\Escaper $escaper
8187
*/
8288
public function __construct(
8389
Action\Context $context,
@@ -86,14 +92,16 @@ public function __construct(
8692
\Magento\Customer\Model\Customer\Mapper $customerMapper,
8793
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
8894
\Psr\Log\LoggerInterface $logger,
89-
AddressRegistry $addressRegistry = null
95+
AddressRegistry $addressRegistry = null,
96+
\Magento\Framework\Escaper $escaper = null
9097
) {
9198
$this->customerRepository = $customerRepository;
9299
$this->resultJsonFactory = $resultJsonFactory;
93100
$this->customerMapper = $customerMapper;
94101
$this->dataObjectHelper = $dataObjectHelper;
95102
$this->logger = $logger;
96103
$this->addressRegistry = $addressRegistry ?: ObjectManager::getInstance()->get(AddressRegistry::class);
104+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
97105
parent::__construct($context);
98106
}
99107

@@ -128,10 +136,14 @@ public function execute()
128136

129137
$postItems = $this->getRequest()->getParam('items', []);
130138
if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
131-
return $resultJson->setData([
132-
'messages' => [__('Please correct the data sent.')],
133-
'error' => true,
134-
]);
139+
return $resultJson->setData(
140+
[
141+
'messages' => [
142+
__('Please correct the data sent.')
143+
],
144+
'error' => true,
145+
]
146+
);
135147
}
136148

137149
foreach (array_keys($postItems) as $customerId) {
@@ -147,10 +159,12 @@ public function execute()
147159
$this->getEmailNotification()->credentialsChanged($this->getCustomer(), $currentCustomer->getEmail());
148160
}
149161

150-
return $resultJson->setData([
151-
'messages' => $this->getErrorMessages(),
152-
'error' => $this->isErrorExists()
153-
]);
162+
return $resultJson->setData(
163+
[
164+
'messages' => $this->getErrorMessages(),
165+
'error' => $this->isErrorExists()
166+
]
167+
);
154168
}
155169

156170
/**
@@ -234,13 +248,16 @@ protected function saveCustomer(CustomerInterface $customer)
234248
$this->disableAddressValidation($customer);
235249
$this->customerRepository->save($customer);
236250
} catch (\Magento\Framework\Exception\InputException $e) {
237-
$this->getMessageManager()->addError($this->getErrorWithCustomerId($e->getMessage()));
251+
$this->getMessageManager()
252+
->addError($this->getErrorWithCustomerId($this->escaper->escapeHtml($e->getMessage())));
238253
$this->logger->critical($e);
239254
} catch (\Magento\Framework\Exception\LocalizedException $e) {
240-
$this->getMessageManager()->addError($this->getErrorWithCustomerId($e->getMessage()));
255+
$this->getMessageManager()
256+
->addError($this->getErrorWithCustomerId($this->escaper->escapeHtml($e->getMessage())));
241257
$this->logger->critical($e);
242258
} catch (\Exception $e) {
243-
$this->getMessageManager()->addError($this->getErrorWithCustomerId('We can\'t save the customer.'));
259+
$this->getMessageManager()
260+
->addError($this->getErrorWithCustomerId('We can\'t save the customer.'));
244261
$this->logger->critical($e);
245262
}
246263
}

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/InlineEditTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Customer\Model\EmailNotificationInterface;
1010
use Magento\Framework\DataObject;
1111
use Magento\Framework\Message\MessageInterface;
12+
use Magento\Framework\Escaper;
1213

1314
/**
1415
* Unit tests for Inline customer edit
@@ -78,6 +79,9 @@ class InlineEditTest extends \PHPUnit\Framework\TestCase
7879
/** @var array */
7980
private $items;
8081

82+
/** @var \Magento\Framework\Escaper */
83+
private $escaper;
84+
8185
/**
8286
* Sets up mocks
8387
*
@@ -86,7 +90,7 @@ class InlineEditTest extends \PHPUnit\Framework\TestCase
8690
protected function setUp()
8791
{
8892
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
89-
93+
$this->escaper = new Escaper();
9094
$this->request = $this->getMockForAbstractClass(
9195
\Magento\Framework\App\RequestInterface::class,
9296
[],
@@ -172,7 +176,8 @@ protected function setUp()
172176
'addressDataFactory' => $this->addressDataFactory,
173177
'addressRepository' => $this->addressRepository,
174178
'logger' => $this->logger,
175-
'addressRegistry' => $this->addressRegistry
179+
'addressRegistry' => $this->addressRegistry,
180+
'escaper' => $this->escaper,
176181
]
177182
);
178183
$reflection = new \ReflectionClass(get_class($this->controller));
@@ -291,10 +296,14 @@ protected function prepareMocksForErrorMessagesProcessing()
291296
->willReturn('Error text');
292297
$this->resultJson->expects($this->once())
293298
->method('setData')
294-
->with([
295-
'messages' => ['Error text'],
296-
'error' => true,
297-
])
299+
->with(
300+
[
301+
'messages' => [
302+
'Error text',
303+
],
304+
'error' => true,
305+
]
306+
)
298307
->willReturnSelf();
299308
}
300309

@@ -340,10 +349,14 @@ public function testExecuteWithoutItems()
340349
$this->resultJson
341350
->expects($this->once())
342351
->method('setData')
343-
->with([
344-
'messages' => [__('Please correct the data sent.')],
345-
'error' => true,
346-
])
352+
->with(
353+
[
354+
'messages' => [
355+
__('Please correct the data sent.'),
356+
],
357+
'error' => true,
358+
]
359+
)
347360
->willReturnSelf();
348361
$this->assertSame($this->resultJson, $this->controller->execute());
349362
}
@@ -365,6 +378,7 @@ public function testExecuteLocalizedException()
365378
->method('save')
366379
->with($this->customerData)
367380
->willThrowException($exception);
381+
368382
$this->messageManager->expects($this->once())
369383
->method('addError')
370384
->with('[Customer ID: 12] Exception message');

0 commit comments

Comments
 (0)