Skip to content

Commit 0e186a4

Browse files
committed
AC-7737: Incompatible issues fix for PHP8.2, Encoding and decoding issue in mb_convert_encoding
1 parent 96f4630 commit 0e186a4

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

app/code/Magento/Sales/Helper/Admin.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ public function escapeHtmlWithLinks($data, $allowedTags = null)
166166

167167
$internalErrors = libxml_use_internal_errors(true);
168168

169-
// $data = mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');
169+
$convmap = [0x80, 0x10FFFF, 0, 0x1FFFFF];
170+
$data = mb_encode_numericentity(
171+
$data,
172+
$convmap,
173+
'UTF-8'
174+
);
175+
170176
$domDocument->loadHTML(
171177
'<html><body id="' . $wrapperElementId . '">' . $data . '</body></html>'
172178
);
@@ -191,8 +197,7 @@ public function escapeHtmlWithLinks($data, $allowedTags = null)
191197
}
192198
}
193199
}
194-
195-
// $result = mb_convert_encoding($domDocument->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
200+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
196201
$result = html_entity_decode($domDocument->saveHTML(), ENT_QUOTES, 'UTF-8');
197202

198203
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);

lib/internal/Magento/Framework/Escaper.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ function ($errorNumber, $errorString) {
9797
}
9898
);
9999
$data = $this->prepareUnescapedCharacters($data);
100-
$string = $data; //mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8');
100+
$convmap = [0x80, 0x10FFFF, 0, 0x1FFFFF];
101+
$string = mb_encode_numericentity(
102+
$data,
103+
$convmap,
104+
'UTF-8'
105+
);
101106
try {
102107
$domDocument->loadHTML(
103108
'<html><body id="' . $wrapperElementId . '">' . $string . '</body></html>'
@@ -114,7 +119,6 @@ function ($errorNumber, $errorString) {
114119
$this->escapeText($domDocument);
115120
$this->escapeAttributeValues($domDocument);
116121

117-
// $result = mb_convert_encoding($domDocument->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
118122
$result = html_entity_decode($domDocument->saveHTML(), ENT_QUOTES, 'UTF-8');
119123

120124
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);
@@ -349,6 +353,7 @@ public function escapeCss($string)
349353
* @param string $quote
350354
* @return string|array
351355
* @deprecated 101.0.0
356+
* @see MAGETWO-54971
352357
*/
353358
public function escapeJsQuote($data, $quote = '\'')
354359
{
@@ -369,6 +374,7 @@ public function escapeJsQuote($data, $quote = '\'')
369374
* @param string $data
370375
* @return string
371376
* @deprecated 101.0.0
377+
* @see MAGETWO-54971
372378
*/
373379
public function escapeXssInUrl($data)
374380
{
@@ -417,6 +423,7 @@ private function escapeScriptIdentifiers(string $data): string
417423
* @param bool $addSlashes
418424
* @return string
419425
* @deprecated 101.0.0
426+
* @see MAGETWO-54971
420427
*/
421428
public function escapeQuote($data, $addSlashes = false)
422429
{
@@ -431,6 +438,7 @@ public function escapeQuote($data, $addSlashes = false)
431438
*
432439
* @return \Magento\Framework\ZendEscaper
433440
* @deprecated 101.0.0
441+
* @see MAGETWO-54971
434442
*/
435443
private function getEscaper()
436444
{
@@ -446,6 +454,7 @@ private function getEscaper()
446454
*
447455
* @return \Psr\Log\LoggerInterface
448456
* @deprecated 101.0.0
457+
* @see MAGETWO-54971
449458
*/
450459
private function getLogger()
451460
{

0 commit comments

Comments
 (0)