Skip to content

Commit 01008af

Browse files
committed
Merge remote-tracking branch 'origin/MC-35152' into 2.4-develop-pr32
2 parents a1a0af9 + f780505 commit 01008af

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

app/code/Magento/Payment/Block/Transparent/Redirect.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,21 @@ public function getRedirectUrl(): string
5353
/**
5454
* Returns params to be redirected.
5555
*
56+
* Encodes invalid UTF-8 values to UTF-8 to prevent character escape error.
57+
* Some payment methods like PayPal, send data in merchant defined language encoding
58+
* which can be different from the system character encoding (UTF-8).
59+
*
5660
* @return array
5761
*/
5862
public function getPostParams(): array
5963
{
60-
return (array)$this->_request->getPostValue();
64+
$params = [];
65+
foreach ($this->_request->getPostValue() as $name => $value) {
66+
if (!empty($value) && mb_detect_encoding($value, 'UTF-8', true) === false) {
67+
$value = utf8_encode($value);
68+
}
69+
$params[$name] = $value;
70+
}
71+
return $params;
6172
}
6273
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Payment\Test\Unit\Block\Transparent;
9+
10+
use Magento\Payment\Block\Transparent\Redirect;
11+
use PHPUnit\Framework\TestCase;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
14+
class RedirectTest extends TestCase
15+
{
16+
/**
17+
* @var \Magento\Framework\View\Element\Context|MockObject
18+
*/
19+
private $context;
20+
/**
21+
* @var \Magento\Framework\UrlInterface|MockObject
22+
*/
23+
private $url;
24+
/**
25+
* @var Redirect
26+
*/
27+
private $model;
28+
/**
29+
* @var \Magento\Framework\App\RequestInterface|MockObject
30+
*/
31+
private $request;
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
protected function setUp(): void
37+
{
38+
parent::setUp();
39+
$this->context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
40+
$this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
41+
$this->context->method('getRequest')
42+
->willReturn($this->request);
43+
$this->url = $this->createMock(\Magento\Framework\UrlInterface::class);
44+
$this->model = new Redirect(
45+
$this->context,
46+
$this->url
47+
);
48+
}
49+
50+
/**
51+
* @param array $postData
52+
* @param array $expected
53+
* @dataProvider getPostParamsDataProvider
54+
*/
55+
public function testGetPostParams(array $postData, array $expected): void
56+
{
57+
$this->request->method('getPostValue')
58+
->willReturn($postData);
59+
$this->assertEquals($expected, $this->model->getPostParams());
60+
}
61+
62+
/**
63+
* @return array
64+
*/
65+
public function getPostParamsDataProvider(): array
66+
{
67+
return [
68+
[
69+
[
70+
'BILLTOEMAIL' => '[email protected]',
71+
'BILLTOSTREET' => '3640 Holdrege Ave',
72+
'BILLTOZIP' => '90016',
73+
'BILLTOLASTNAME' => 'Ãtienne',
74+
'BILLTOFIRSTNAME' => 'Ãillin',
75+
],
76+
[
77+
'BILLTOEMAIL' => '[email protected]',
78+
'BILLTOSTREET' => '3640 Holdrege Ave',
79+
'BILLTOZIP' => '90016',
80+
'BILLTOLASTNAME' => 'Ãtienne',
81+
'BILLTOFIRSTNAME' => 'Ãillin',
82+
]
83+
],
84+
[
85+
[
86+
'BILLTOEMAIL' => '[email protected]',
87+
'BILLTOSTREET' => '3640 Holdrege Ave',
88+
'BILLTOZIP' => '90016',
89+
'BILLTOLASTNAME' => mb_convert_encoding('Ãtienne', 'ISO-8859-1'),
90+
'BILLTOFIRSTNAME' => mb_convert_encoding('Ãillin', 'ISO-8859-1'),
91+
],
92+
[
93+
'BILLTOEMAIL' => '[email protected]',
94+
'BILLTOSTREET' => '3640 Holdrege Ave',
95+
'BILLTOZIP' => '90016',
96+
'BILLTOLASTNAME' => 'Ãtienne',
97+
'BILLTOFIRSTNAME' => 'Ãillin',
98+
]
99+
]
100+
];
101+
}
102+
}

0 commit comments

Comments
 (0)