N°2982 - Speed up SCSS themes compilation during setup - fix infite loop when n signature inside precompiled file

This commit is contained in:
odain
2021-03-31 23:37:29 +02:00
parent 6744147bf9
commit cb91d6f3c4
2 changed files with 13 additions and 3 deletions

View File

@@ -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;

View File

@@ -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');