Skip to content

Commit 0b3788b

Browse files
author
Yaroslav Voronoy
committed
MDVA-210: HTML template minification does not properly handle commented code
Conflicts: lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php
1 parent b6bb8e5 commit 0b3788b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ public function minify($file)
131131
preg_replace(
132132
'#(?<!:)//[^\n\r]*(\s\?\>)#',
133133
'$1',
134-
$this->rootDirectory->readFile($file)
134+
preg_replace(
135+
'#//[^\n\r]*(\<\?php)[^\n\r]*(\s\?\>)[^\n\r]*#',
136+
'',
137+
$this->rootDirectory->readFile($file)
138+
)
135139
)
136140
)
137141
)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public function testMinify()
9898
<?php echo \$block->someMethod(); ?>
9999
<div style="width: 800px" class="<?php echo \$block->getClass() ?>" />
100100
<script>
101+
var i = 1;// comment
102+
var j = 1;// <?php echo 'hi' ?>
103+
//<?php ?> ')){
104+
// if (<?php echo __('hi')) { ?>
101105
//<![CDATA[
102106
var someVar = 123;
103107
testFunctionCall(function () {
@@ -118,6 +122,10 @@ public function testMinify()
118122

119123
$expectedContent = <<<TEXT
120124
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ ?> <?php ?> <html><head><title>Test title</title></head><body><a href="http://somelink.com/text.html">Text Link</a> <img src="test.png" alt="some text" /><?php echo \$block->someMethod(); ?> <div style="width: 800px" class="<?php echo \$block->getClass() ?>" /><script>
125+
var i = 1;
126+
var j = 1;
127+
128+
121129
//<![CDATA[
122130
var someVar = 123;
123131
testFunctionCall(function () {

0 commit comments

Comments
 (0)