Skip to content

Commit 1eebe6c

Browse files
committed
Only detect and remove <script> attributes
Before this change, the sniff would alert on (and remove) any non-PHP text which matched, not only <script> attributes.
1 parent 1681210 commit 1eebe6c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ private function checkBlockVariable(File $phpcsFile, int $stackPtr, array $token
7474
private function checkHtml(File $phpcsFile, int $stackPtr): void
7575
{
7676
$content = $phpcsFile->getTokensAsString($stackPtr, 1);
77-
$pattern = '_\s+type=(["\'])text/javascript\1_i';
77+
$pattern = '_(<script[^>\s]*)\stype=(["\'])text/javascript\2_i';
7878

79-
if (preg_match($pattern, $content)) {
79+
if (preg_match($pattern, $content, $matches)) {
8080
$fix = $phpcsFile->addFixableWarning(
8181
'Please do not use "text/javascript" type attribute.',
8282
$stackPtr,
8383
self::WARNING_CODE_TEXT_JAVASCRIPT
8484
);
8585

8686
if ($fix) {
87-
$content = preg_replace($pattern, '', $content);
87+
$content = preg_replace($pattern, $matches[1], $content);
8888
$phpcsFile->fixer->replaceToken($stackPtr, $content);
8989
}
9090
}

0 commit comments

Comments
 (0)