Skip to content

Commit bdf7a1e

Browse files
author
mastiuhin-olexandr
committed
MC-23553: Invalid Template Strings when Translate Inline enabled
1 parent 88e4207 commit bdf7a1e

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lib/internal/Magento/Framework/Escaper.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,22 +495,27 @@ private function getTranslateInline()
495495
private function inlineSensitiveEscapeHthmlAttr(string $text): string
496496
{
497497
$escaper = $this->getEscaper();
498+
$textLength = strlen($text);
499+
500+
if ($textLength < 6) {
501+
return $escaper->escapeHtmlAttr($text);
502+
}
503+
498504
$firstCharacters = substr($text, 0, 3);
499505
$lastCharacters = substr($text, -3, 3);
500506

501-
if ($firstCharacters === '{{{' && $lastCharacters === '}}}') {
502-
$textLength = strlen($text);
503-
$text = substr($text, 3, $textLength - 6);
504-
$strings = explode('}}{{', $text);
505-
$escapedStrings = [];
507+
if ($firstCharacters !== '{{{' || $lastCharacters !== '}}}') {
508+
return $escaper->escapeHtmlAttr($text);
509+
}
506510

507-
foreach ($strings as $string) {
508-
$escapedStrings[] = $escaper->escapeHtmlAttr($string);
509-
}
511+
$text = substr($text, 3, $textLength - 6);
512+
$strings = explode('}}{{', $text);
513+
$escapedStrings = [];
510514

511-
return '{{{' . implode('}}{{', $escapedStrings) . '}}}';
515+
foreach ($strings as $string) {
516+
$escapedStrings[] = $escaper->escapeHtmlAttr($string);
512517
}
513518

514-
return $escaper->escapeHtmlAttr($text);
519+
return '{{{' . implode('}}{{', $escapedStrings) . '}}}';
515520
}
516521
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public function testEscapeHtml($data, $expected, $allowedTags = [])
181181
* @param string $input
182182
* @param string $output
183183
* @return void
184-
* @dataProvider escapeHtmlAttrWithInlineProvider
184+
* @dataProvider escapeHtmlAttributeWithInlineTranslateEnabledDataProvider
185185
*/
186-
public function testEscapeHtmlAttrWithInline(string $input, string $output): void
186+
public function testEscapeHtmlAttributeWithInlineTranslateEnabled(string $input, string $output): void
187187
{
188188
$this->objectManagerHelper->setBackwardCompatibleProperty(
189189
$this->translateInline,
@@ -209,7 +209,7 @@ public function testEscapeHtmlAttrWithInline(string $input, string $output): voi
209209
*
210210
* @return array
211211
*/
212-
public function escapeHtmlAttrWithInlineProvider(): array
212+
public function escapeHtmlAttributeWithInlineTranslateEnabledDataProvider(): array
213213
{
214214
return [
215215
[

0 commit comments

Comments
 (0)