Skip to content

Commit 03c2d71

Browse files
Merge pull request #8088 from magento-gl/Hammer_Regression_Blocker_Encoding_decodings_19jan22
Hammer regression blocker encoding decodings 19jan22
2 parents 6d8bd27 + f2ac7d9 commit 03c2d71

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

app/code/Magento/GraphQl/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"magento/module-webapi": "*",
1010
"magento/module-new-relic-reporting": "*",
1111
"magento/module-authorization": "*",
12-
"webonyx/graphql-php": "^14.11"
12+
"webonyx/graphql-php": "^15.0"
1313
},
1414
"suggest": {
1515
"magento/module-graph-ql-cache": "*"

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

Lines changed: 18 additions & 2 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
);
@@ -192,7 +198,17 @@ public function escapeHtmlWithLinks($data, $allowedTags = null)
192198
}
193199
}
194200

195-
$result = mb_convert_encoding($domDocument->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
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+
);
211+
196212
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);
197213
$data = !empty($matches) ? $matches[1] : '';
198214
}

lib/internal/Magento/Framework/Escaper.php

Lines changed: 22 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 = 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,17 @@ function ($errorNumber, $errorString) {
114119
$this->escapeText($domDocument);
115120
$this->escapeAttributeValues($domDocument);
116121

117-
$result = mb_convert_encoding($domDocument->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
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+
);
132+
118133
preg_match('/<body id="' . $wrapperElementId . '">(.+)<\/body><\/html>$/si', $result, $matches);
119134
return !empty($matches) ? $matches[1] : '';
120135
} else {
@@ -347,6 +362,7 @@ public function escapeCss($string)
347362
* @param string $quote
348363
* @return string|array
349364
* @deprecated 101.0.0
365+
* @see MAGETWO-54971
350366
*/
351367
public function escapeJsQuote($data, $quote = '\'')
352368
{
@@ -367,6 +383,7 @@ public function escapeJsQuote($data, $quote = '\'')
367383
* @param string $data
368384
* @return string
369385
* @deprecated 101.0.0
386+
* @see MAGETWO-54971
370387
*/
371388
public function escapeXssInUrl($data)
372389
{
@@ -415,6 +432,7 @@ private function escapeScriptIdentifiers(string $data): string
415432
* @param bool $addSlashes
416433
* @return string
417434
* @deprecated 101.0.0
435+
* @see MAGETWO-54971
418436
*/
419437
public function escapeQuote($data, $addSlashes = false)
420438
{
@@ -429,6 +447,7 @@ public function escapeQuote($data, $addSlashes = false)
429447
*
430448
* @return \Magento\Framework\ZendEscaper
431449
* @deprecated 101.0.0
450+
* @see MAGETWO-54971
432451
*/
433452
private function getEscaper()
434453
{
@@ -444,6 +463,7 @@ private function getEscaper()
444463
*
445464
* @return \Psr\Log\LoggerInterface
446465
* @deprecated 101.0.0
466+
* @see MAGETWO-54971
447467
*/
448468
private function getLogger()
449469
{

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)