Skip to content

Commit 420ab7e

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-91699: Displaying of error messages in a customer account is broken
1 parent 2ae0b65 commit 420ab7e

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Customer\Model\CustomerExtractor;
2323
use Magento\Customer\Model\Session;
2424
use Magento\Framework\App\Action\Context;
25+
use Magento\Framework\Escaper;
2526
use Magento\Framework\Exception\InputException;
2627
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
2728
use Magento\Framework\Exception\State\UserLockedException;
@@ -79,28 +80,36 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http
7980
*/
8081
private $customerMapper;
8182

83+
/**
84+
* @var Escaper
85+
*/
86+
private $escaper;
87+
8288
/**
8389
* @param Context $context
8490
* @param Session $customerSession
8591
* @param AccountManagementInterface $customerAccountManagement
8692
* @param CustomerRepositoryInterface $customerRepository
8793
* @param Validator $formKeyValidator
8894
* @param CustomerExtractor $customerExtractor
95+
* @param Escaper|null $escaper
8996
*/
9097
public function __construct(
9198
Context $context,
9299
Session $customerSession,
93100
AccountManagementInterface $customerAccountManagement,
94101
CustomerRepositoryInterface $customerRepository,
95102
Validator $formKeyValidator,
96-
CustomerExtractor $customerExtractor
103+
CustomerExtractor $customerExtractor,
104+
?Escaper $escaper = null
97105
) {
98106
parent::__construct($context);
99107
$this->session = $customerSession;
100108
$this->customerAccountManagement = $customerAccountManagement;
101109
$this->customerRepository = $customerRepository;
102110
$this->formKeyValidator = $formKeyValidator;
103111
$this->customerExtractor = $customerExtractor;
112+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
104113
}
105114

106115
/**
@@ -196,7 +205,7 @@ public function execute()
196205
$this->messageManager->addSuccess(__('You saved the account information.'));
197206
return $resultRedirect->setPath('customer/account');
198207
} catch (InvalidEmailOrPasswordException $e) {
199-
$this->messageManager->addError($e->getMessage());
208+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
200209
} catch (UserLockedException $e) {
201210
$message = __(
202211
'The account sign-in was incorrect or your account is disabled temporarily. '
@@ -207,9 +216,9 @@ public function execute()
207216
$this->messageManager->addError($message);
208217
return $resultRedirect->setPath('customer/account/login');
209218
} catch (InputException $e) {
210-
$this->messageManager->addError($e->getMessage());
219+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
211220
foreach ($e->getErrors() as $error) {
212-
$this->messageManager->addError($error->getMessage());
221+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage()));
213222
}
214223
} catch (\Magento\Framework\Exception\LocalizedException $e) {
215224
$this->messageManager->addError($e->getMessage());

dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ public function testMissingDataEditPostAction()
606606

607607
$this->assertRedirect($this->stringContains('customer/account/edit/'));
608608
$this->assertSessionMessages(
609-
$this->equalTo(['"Email" is not a valid email address.']),
609+
$this->equalTo(['"Email" is not a valid email address.']),
610610
MessageInterface::TYPE_ERROR
611611
);
612612
}
@@ -637,7 +637,7 @@ public function testWrongPasswordEditPostAction()
637637
$this->assertRedirect($this->stringContains('customer/account/edit/'));
638638
// Not sure if its the most secure message. Not changing the behavior for now in the new AccountManagement APIs.
639639
$this->assertSessionMessages(
640-
$this->equalTo(["The password doesn't match this account. Verify the password and try again."]),
640+
$this->equalTo(["The password doesn't match this account. Verify the password and try again."]),
641641
MessageInterface::TYPE_ERROR
642642
);
643643
}
@@ -665,7 +665,7 @@ public function testWrongConfirmationEditPostAction()
665665

666666
$this->assertRedirect($this->stringContains('customer/account/edit/'));
667667
$this->assertSessionMessages(
668-
$this->equalTo(['Password confirmation doesn\'t match entered password.']),
668+
$this->equalTo(['Password confirmation doesn't match entered password.']),
669669
MessageInterface::TYPE_ERROR
670670
);
671671
}

0 commit comments

Comments
 (0)