Skip to content

Commit a52af42

Browse files
committed
AC-7737: Incompatible issues fix for PHP8.2, Encoding and decoding issue in mb_convert_encoding
1 parent 7bc2c24 commit a52af42

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,17 @@ public function escapeHtmlWithLinks($data, $allowedTags = null)
197197
}
198198
}
199199
}
200-
// phpcs:ignore Magento2.Functions.DiscouragedFunction
201-
$result = html_entity_decode($domDocument->saveHTML(), ENT_QUOTES, 'UTF-8');
200+
201+
$result = mb_decode_numericentity(
202+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
203+
html_entity_decode(
204+
$domDocument->saveHTML(),
205+
ENT_QUOTES|ENT_SUBSTITUTE,
206+
'UTF-8'
207+
),
208+
$convmap,
209+
'UTF-8'
210+
);
202211

203212
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);
204213
$data = !empty($matches) ? $matches[1] : '';

lib/internal/Magento/Framework/Escaper.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,16 @@ function ($errorNumber, $errorString) {
119119
$this->escapeText($domDocument);
120120
$this->escapeAttributeValues($domDocument);
121121

122-
$result = html_entity_decode($domDocument->saveHTML(), ENT_QUOTES, 'UTF-8');
122+
$result = mb_decode_numericentity(
123+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
124+
html_entity_decode(
125+
$domDocument->saveHTML(),
126+
ENT_QUOTES|ENT_SUBSTITUTE,
127+
'UTF-8'
128+
),
129+
$convmap,
130+
'UTF-8'
131+
);
123132

124133
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);
125134
return !empty($matches) ? $matches[1] : '';

lib/internal/Magento/Framework/Test/Unit/EscaperTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ public function escapeHtmlDataProvider()
328328
'expected' => ' some text',
329329
'allowedTags' => ['span'],
330330
],
331+
'text with japanese lang' => [
332+
'data' => '<span>だ だ だ some text in tags<br /></span>',
333+
'expected' => '<span>だ だ だ some text in tags</span>',
334+
'allowedTags' => ['span'],
335+
],
331336
];
332337
}
333338

0 commit comments

Comments
 (0)