From 3aa168213196bffa5252405c79e230af08723a76 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Mon, 17 May 2021 20:05:35 +0300 Subject: [PATCH] check BOM in the Framework rule --- .../language/en-GB/en-GB.com_jedchecker.ini | 1 + .../com_jedchecker/libraries/rules/framework.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini index cf9a780..48313da 100644 --- a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini +++ b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini @@ -55,6 +55,7 @@ COM_JEDCHECKER_OLD_RULE_X_PHP_FILE_REMOVED="Removed PHP file for '%s' rule." COM_JEDCHECKER_OLD_RULE_X_INI_FILE_REMOVED="Removed 'ini' file for '%s' rule." COM_JEDCHECKER_RULE_FRAMEWORK="Joomla Framework deprecated and unsafe" COM_JEDCHECKER_RULE_FRAMEWORK_DESC="Warns about Find more info on Joomla! backward compatibility for Joomla! 3 and Joomla! 4" +COM_JEDCHECKER_ERROR_FRAMEWORK_BOM_FOUND="The byte order mark (BOM) is detected" COM_JEDCHECKER_ERROR_FRAMEWORK_SHORT_PHP_TAG="Short PHP tag found. As short tags can be disabled in PHP, it is recommended to only use the normal tags (<?php) to maximise compatibility." COM_JEDCHECKER_ERROR_FRAMEWORK_SUPERGLOBALS="Use of superglobals is strongly discouraged" COM_JEDCHECKER_ERROR_FRAMEWORK_DIRECTDB="Use of direct database access is strongly discouraged" diff --git a/administrator/components/com_jedchecker/libraries/rules/framework.php b/administrator/components/com_jedchecker/libraries/rules/framework.php index ccfa819..9aeb8fb 100644 --- a/administrator/components/com_jedchecker/libraries/rules/framework.php +++ b/administrator/components/com_jedchecker/libraries/rules/framework.php @@ -140,15 +140,23 @@ class JedcheckerRulesFramework extends JEDcheckerRule return false; } + $result = false; + $content = file_get_contents($file); + + // Check BOM + if (strncmp($content, "\xEF\xBB\xBF", 3) === 0) + { + $this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_FRAMEWORK_BOM_FOUND')); + $result = true; + } + $content = JEDCheckerHelper::cleanPhpCode( $content, JEDCheckerHelper::CLEAN_HTML | JEDCheckerHelper::CLEAN_COMMENTS | JEDCheckerHelper::CLEAN_STRINGS ); $cleanContent = JEDCheckerHelper::splitLines($content); - $result = false; - if (preg_match('/<\?\s/', $content, $match, PREG_OFFSET_CAPTURE)) { $lineno = substr_count($content, "\n", 0, $match[0][1]);