Skip to content

Commit 6341225

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

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

app/code/Magento/Translation/Model/Inline/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private function _prepareTagAttributesForContent(&$content)
475475
} else {
476476
$trAttr = ' ' . $this->_getHtmlAttribute(
477477
self::DATA_TRANSLATE,
478-
'[' . str_replace("\"", "'", join(',', $trArr)) . ']'
478+
'[' . str_replace("\"", """, join(',', $trArr)) . ']'
479479
);
480480
}
481481
$trAttr = $this->_addTranslateAttribute($trAttr);

app/code/Magento/Translation/Test/Unit/Model/Inline/ParserTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ public function testProcessResponseBodyStringProcessingAttributesCorrectly()
147147
{
148148
$testContent = file_get_contents(__DIR__ . '/_files/datatranslate_fixture.html');
149149
$processedAttributes = [
150-
"data-translate=\"[{'shown':'* Required Fields','translated':'* Required Fields',"
151-
. "'original':'* Required Fields','location':'Tag attribute (ALT, TITLE, etc.)'}]\"",
152-
"data-translate=\"[{'shown':'Email','translated':'Email','original':'Email',"
153-
. "'location':'Tag attribute (ALT, TITLE, etc.)'}]\"",
154-
"data-translate=\"[{'shown':'Password','translated':'Password','original':'Password',"
155-
. "'location':'Tag attribute (ALT, TITLE, etc.)'}]\""
150+
"data-translate=\"[{"shown":"* Required Fields","translated":"* Required Fields","
151+
. ""original":"* Required Fields","location":"Tag attribute (ALT, TITLE, etc.)"}]\"",
152+
"data-translate=\"[{"shown":"Email","translated":"Email","original":"Email","
153+
. ""location":"Tag attribute (ALT, TITLE, etc.)"}]\"",
154+
"data-translate=\"[{"shown":"Password","translated":"Password","original":"Password","
155+
. ""location":"Tag attribute (ALT, TITLE, etc.)"}]\""
156156
];
157157
$this->translateInlineMock->method('getAdditionalHtmlAttribute')->willReturn(null);
158158

lib/internal/Magento/Framework/Escaper.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,17 @@ private function escapeAttributeValue($name, $value)
258258
*/
259259
public function escapeHtmlAttr($string, $escapeSingleQuote = true)
260260
{
261+
$string = (string)$string;
262+
261263
if ($escapeSingleQuote) {
262264
$translateInline = $this->getTranslateInline();
263265

264-
if ($translateInline->isAllowed()) {
265-
return $this->inlineSensitiveEscapeHthmlAttr((string) $string);
266-
}
267-
268-
return $this->getEscaper()
269-
->escapeHtmlAttr((string) $string);
266+
return $translateInline->isAllowed()
267+
? $this->inlineSensitiveEscapeHthmlAttr($string)
268+
: $this->getEscaper()->escapeHtmlAttr($string);
270269
}
271270

272-
return htmlspecialchars((string)$string, $this->htmlSpecialCharsFlag, 'UTF-8', false);
271+
return htmlspecialchars($string, $this->htmlSpecialCharsFlag, 'UTF-8', false);
273272
}
274273

275274
/**

0 commit comments

Comments
 (0)