Skip to content

Commit

Permalink
Merge pull request #3 from pluswerk/bugfix/preserve-correct-comments
Browse files Browse the repository at this point in the history
Preserve correct TYPO3 comment and don't throw errors if no comment i…
  • Loading branch information
theobscenezen authored Oct 23, 2019
2 parents 158a042 + 5670f15 commit e2c1a5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions Classes/Service/HtmlMinifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

// Not nice but this is really hardcoded in the core.
if ($this->isFeatureActive('remove_comments')) {
$typo3CommentStart = strpos($html, '<!--');
$typo3CommentStop = strpos($html, '-->', $typo3CommentStart);
$typo3Comment = substr($html, $typo3CommentStart, $typo3CommentStop - $typo3CommentStart + 3);
$output = [];

$typo3Comment = $this->preserveTypo3Comment($html);

$html = $htmlMin->minify($html);
$output = [];
$languageMeta = preg_match_all('/<meta charset=[a-zA-Z0-9-_"]*>/', $html, $output);
if ($languageMeta) {
$insertAt = strpos($html, $output[0][0]) + strlen($output[0][0]);
Expand Down Expand Up @@ -103,4 +103,22 @@ protected function isFeatureActive(string $feature): bool
{
return isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify'][$feature]) && $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify'][$feature] === '1';
}

private function preserveTypo3Comment(string $html): string
{
$typo3CommentStart = strpos($html, '<!--');
if ($typo3CommentStart !== false) {
$typo3CommentStop = strpos($html, '-->', $typo3CommentStart);
$typo3Comment = substr($html, $typo3CommentStart, $typo3CommentStop - $typo3CommentStart + 3);

if (strpos($typo3Comment, 'TYPO3') !== false) {
return $typo3Comment;
}

$html = str_replace($typo3Comment, '', $html);
return $this->preserveTypo3Comment($html);
}

return '';
}
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'uploadfolder' => '0',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '1.0.4',
'version' => '1.0.5',
'constraints' =>[
'depends' => [
'typo3' => '9.5.0-9.99.99',
Expand Down

0 comments on commit e2c1a5f

Please sign in to comment.