Skip to content

Commit 74727b2

Browse files
author
Oleksandr Gorkun
committed
MC-35064: [Cloud] Can't deploy 2.4.0-alpha8 on cloud pro instance
1 parent c1754e9 commit 74727b2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/internal/Magento/Framework/View/Template/Html/Minifier.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ public function minify($file)
114114
{
115115
$dir = dirname($file);
116116
$fileName = basename($file);
117+
$content = $this->readFactory->create($dir)->readFile($fileName);
118+
//Storing Heredocs
119+
$heredocs = [];
120+
$content = preg_replace_callback(
121+
'/<<<([A-z]+).*?\1;/ims',
122+
function ($match) use (&$heredocs) {
123+
$heredocs[] = $match[0];
124+
125+
return '__MINIFIED_HEREDOC__' .(count($heredocs) - 1);
126+
},
127+
$content
128+
);
117129
$content = preg_replace(
118130
'#(?<!]]>)\s+</#',
119131
'</',
@@ -136,7 +148,7 @@ public function minify($file)
136148
preg_replace(
137149
'#(?<!:)//[^\n\r]*(\<\?php)[^\n\r]*(\s\?\>)[^\n\r]*#',
138150
'',
139-
$this->readFactory->create($dir)->readFile($fileName)
151+
$content
140152
)
141153
)
142154
)
@@ -145,6 +157,15 @@ public function minify($file)
145157
)
146158
);
147159

160+
//Restoring Heredocs
161+
$content = preg_replace_callback(
162+
'/__MINIFIED_HEREDOC__(\d+)/ims',
163+
function ($match) use ($heredocs) {
164+
return $heredocs[(int)$match[1]];
165+
},
166+
$content
167+
);
168+
148169
if (!$this->htmlDirectory->isExist()) {
149170
$this->htmlDirectory->create();
150171
}

lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ public function testMinify()
167167
<?php // echo \$block->getChildHtml('anotherChildBlock'); ?>
168168
<?php // endif; ?>
169169
</body>
170+
<?php
171+
\$sometext = <<<SOMETEXT
172+
mytext
173+
mytextline2
174+
SOMETEXT;
175+
?>
170176
</html>
171177
TEXT;
172178

@@ -189,7 +195,10 @@ public function testMinify()
189195
}
190196
});
191197
//]]>
192-
</script><?php echo "http://some.link.com/" ?> <?php echo "//some.link.com/" ?> <?php echo '//some.link.com/' ?> <em>inline text</em> <a href="http://www.<?php echo 'hi' ?>"></a> <?php ?> <?php echo \$block->getChildHtml('someChildBlock'); ?> <?php ?> <?php ?> <?php ?></body></html>
198+
</script><?php echo "http://some.link.com/" ?> <?php echo "//some.link.com/" ?> <?php echo '//some.link.com/' ?> <em>inline text</em> <a href="http://www.<?php echo 'hi' ?>"></a> <?php ?> <?php echo \$block->getChildHtml('someChildBlock'); ?> <?php ?> <?php ?> <?php ?></body><?php \$sometext = <<<SOMETEXT
199+
mytext
200+
mytextline2
201+
SOMETEXT; ?></html>
193202
TEXT;
194203

195204
$this->appDirectoryMock->expects($this->once())

0 commit comments

Comments
 (0)