Skip to content

Commit a02d821

Browse files
committed
MC-19247: Broken translations with advanced bundling
- Add escape url to layout;
1 parent 341a587 commit a02d821

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

app/code/Magento/Translation/ViewModel/Dictionary.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Translation\ViewModel;
88

9+
use Magento\Framework\Escaper;
910
use Magento\Framework\Exception\FileSystemException;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\View\Asset\Repository as AssetRepository;
@@ -28,16 +29,24 @@ class Dictionary implements ArgumentInterface
2829
*/
2930
private $appState;
3031

32+
/**
33+
* @var Escaper
34+
*/
35+
private $escaper;
36+
3137
/**
3238
* @param AssetRepository $assetRepo
3339
* @param AppState $appState
40+
* @param Escaper $escaper
3441
*/
3542
public function __construct(
3643
AssetRepository $assetRepo,
37-
AppState $appState
44+
AppState $appState,
45+
Escaper $escaper
3846
) {
3947
$this->assetRepo = $assetRepo;
4048
$this->appState = $appState;
49+
$this->escaper = $escaper;
4150
}
4251

4352
/**
@@ -76,4 +85,15 @@ public function isAppStateProduction(): bool
7685
{
7786
return $this->appState->getMode() === AppState::MODE_PRODUCTION;
7887
}
88+
89+
/**
90+
* Escape URL.
91+
*
92+
* @param string $url
93+
* @return string
94+
*/
95+
public function escapeUrl(string $url): string
96+
{
97+
return $this->escaper->escapeUrl($url);
98+
}
7999
}

app/code/Magento/Translation/view/base/templates/dictionary.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ if (!$viewModel->isAppStateProduction()) {
2020
} else {
2121
?>
2222
<script>
23-
define('mageTranslationDictionary', ['text!<?= /* @noEscape */ $viewModel->getTranslationDictionaryUrl() ?>'], function (dict) {
23+
define('mageTranslationDictionary', ['text!<?= $viewModel->escapeUrl($viewModel->getTranslationDictionaryUrl()) ?>'], function (dict) {
2424
return JSON.parse(dict);
2525
});
2626
</script>
27-
<?php
27+
<?php
2828
}
2929
?>

dev/tests/js/jasmine/tests/lib/mage/fake-dictionary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
// Fake translation dictionary for js unit tests as real dictionary is defined in template and cannot be initialized by requirejs
5+
// Fake translation dictionary as real dictionary is defined in template and cannot be initialized by requirejs
66
define([], function () {
77
'use strict';
88

0 commit comments

Comments
 (0)