From f103832dbdc3582f60725b3e7cbcc2e138d860dd Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Wed, 4 Oct 2017 16:14:40 +0300 Subject: [PATCH] MAGETWO-80207: [2.2.x] - Modified Bundle.js because of breaking Encoding in Production Mode. #10563 --- app/code/Magento/Deploy/Package/Bundle/RequireJs.php | 9 ++++++--- lib/internal/Magento/Framework/View/Asset/Bundle.php | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Deploy/Package/Bundle/RequireJs.php b/app/code/Magento/Deploy/Package/Bundle/RequireJs.php index 73a15554f8b78..c7c9e5315c7ab 100644 --- a/app/code/Magento/Deploy/Package/Bundle/RequireJs.php +++ b/app/code/Magento/Deploy/Package/Bundle/RequireJs.php @@ -240,9 +240,12 @@ private function endBundleFile(WriteInterface $bundleFile, array $contents) private function getFileContent($sourcePath) { if (!isset($this->fileContent[$sourcePath])) { - $this->fileContent[$sourcePath] = utf8_encode( - $this->staticDir->readFile($this->minification->addMinifiedSign($sourcePath)) - ); + $content = $this->staticDir->readFile($this->minification->addMinifiedSign($sourcePath)); + if (mb_detect_encoding($content) !== "UTF-8") { + $content = mb_convert_encoding($content, "UTF-8"); + } + + $this->fileContent[$sourcePath] = $content; } return $this->fileContent[$sourcePath]; } diff --git a/lib/internal/Magento/Framework/View/Asset/Bundle.php b/lib/internal/Magento/Framework/View/Asset/Bundle.php index bdaf13ddbbb27..80f35f9d57075 100644 --- a/lib/internal/Magento/Framework/View/Asset/Bundle.php +++ b/lib/internal/Magento/Framework/View/Asset/Bundle.php @@ -212,7 +212,11 @@ protected function getAssetContent(LocalInterface $asset) $assetContentType = $asset->getContentType(); $assetKey = $this->getAssetKey($asset); if (!isset($this->assetsContent[$assetContextCode][$assetContentType][$assetKey])) { - $this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = utf8_encode($asset->getContent()); + $content = $asset->getContent(); + if (mb_detect_encoding($content) !== "UTF-8") { + $content = mb_convert_encoding($content, "UTF-8"); + } + $this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = $content; } return $this->assetsContent[$assetContextCode][$assetContentType][$assetKey];