From cb91d6f3c4b8a6694690ce78ecaa950ce36a5161 Mon Sep 17 00:00:00 2001 From: odain Date: Wed, 31 Mar 2021 23:37:29 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02982=20-=20Speed=20up=20SCSS=20themes=20?= =?UTF-8?q?compilation=20during=20setup=20-=20fix=20infite=20loop=20when?= =?UTF-8?q?=20n=20signature=20inside=20precompiled=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/themehandler.class.inc.php | 9 ++++++--- test/application/ThemeHandlerTest.php | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/application/themehandler.class.inc.php b/application/themehandler.class.inc.php index 52073bea3..25c5b6734 100644 --- a/application/themehandler.class.inc.php +++ b/application/themehandler.class.inc.php @@ -699,8 +699,9 @@ CSS; /** * @since 3.0.0 N°2982 - * Extract the signature for a generated CSS file. The signature MUST be alone one line immediately - * followed (on the next line) by the === SIGNATURE END === pattern + * Extract the signature for a generated CSS file. + * The signature MUST be alone one line immediately followed (on the next line) by the === SIGNATURE END === pattern + * The signature MUST be in the first 100th lines of the file. * * Note the signature can be place anywhere in the CSS file (obviously inside a CSS comment !) but the * function will be faster if the signature is at the beginning of the file (since the file is scanned from the start) @@ -711,6 +712,7 @@ CSS; */ public static function GetSignature($sFilepath) { + $iCount = 0; $sPreviousLine = ''; $hFile = @fopen($sFilepath, "r"); if ($hFile !== false) @@ -718,10 +720,11 @@ CSS; $sLine = ''; do { + $iCount++; $sPreviousLine = $sLine; $sLine = rtrim(fgets($hFile)); // Remove the trailing \n } - while (($sLine !== false) && ($sLine != '=== SIGNATURE END ===')); + while (($sLine !== false) && ($sLine != '=== SIGNATURE END ===') && ($iCount <= 100)); fclose($hFile); } return $sPreviousLine; diff --git a/test/application/ThemeHandlerTest.php b/test/application/ThemeHandlerTest.php index 2e6b6caf3..9fda00021 100644 --- a/test/application/ThemeHandlerTest.php +++ b/test/application/ThemeHandlerTest.php @@ -223,6 +223,13 @@ class ThemeHandlerTest extends ItopTestCase return @mkdir($dir); } + public function testGetSignatureWithFileWithoutSignature() + { + $sTmpFile = tempnam(sys_get_temp_dir(), "sig"); + file_put_contents($sTmpFile,"ffff"); + $this->assertEquals("", ThemeHandler::GetSignature($sTmpFile)); + } + public function testGetSignature() { $sSig = ThemeHandler::GetSignature(APPROOT.'test/application/theme-handler/expected/themes/basque-red/main.css');