diff --git a/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php b/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php index f020b061..bc44466e 100644 --- a/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php +++ b/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php @@ -74,9 +74,9 @@ private function checkBlockVariable(File $phpcsFile, int $stackPtr, array $token private function checkHtml(File $phpcsFile, int $stackPtr): void { $content = $phpcsFile->getTokensAsString($stackPtr, 1); - $pattern = '_\s+type=(["\'])text/javascript\1_i'; + $pattern = '_(\s]*)\stype=(["\'])text/javascript\2_i'; - if (preg_match($pattern, $content)) { + if (preg_match($pattern, $content, $matches)) { $fix = $phpcsFile->addFixableWarning( 'Please do not use "text/javascript" type attribute.', $stackPtr, @@ -84,7 +84,7 @@ private function checkHtml(File $phpcsFile, int $stackPtr): void ); if ($fix) { - $content = preg_replace($pattern, '', $content); + $content = preg_replace($pattern, $matches[1], $content); $phpcsFile->fixer->replaceToken($stackPtr, $content); } }