Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public function minify($file)
'#(?<!:|\\\\|\'|")//(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#',
'',
preg_replace(
'#(?<!:|\'|")//[^\n\r]*(\s\?\>)#',
'$1',
'#(?<!:|\'|")//[^\n\r]*(\?\>)#',
' $1',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you did not simpy change the regular expression in #(?<!:|'|")//[^\n\r]*(\s*\?\>)#, instead of adding the prefixing space in the replacement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case if the code will be like this one:

<?php//else:?>

if the replacement string will be just '$1', we will get the result:

<?php?>

So it will cause calling of undefined conftant php and to prevent it I added the prefixing space in the replacement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, right point.

preg_replace(
'#(?<!:)//[^\n\r]*(\<\?php)[^\n\r]*(\s\?\>)[^\n\r]*#',
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public function testMinify()
<?php echo '//some.link.com/' ?>
<em>inline text</em>
<a href="http://www.<?php echo 'hi' ?>"></a>
<?php// if (\$block->getSomeVariable() > 1):?>
<?php echo \$block->getChildHtml('someChildBlock'); ?>
<?php //else:?>
<?php // echo \$block->getChildHtml('anotherChildBlock'); ?>
<?php // endif; ?>
</body>
</html>
TEXT;
Expand All @@ -179,7 +184,7 @@ public function testMinify()
}
});
//]]>
</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></body></html>
</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>
TEXT;

$this->appDirectoryMock->expects($this->once())
Expand Down