From 1e3c425e81b4fae3bf16647927119762129a93f6 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Wed, 10 Jul 2024 10:07:12 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B07645=20-=20PHP=208.1:=20Fix=20usage=20of?= =?UTF-8?q?=20strpos()=20&=20str=5Freplace()=20with=20null=20value=20when?= =?UTF-8?q?=20compiling=20empty=20dictionary=20(#600)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(compiler): provide empty string instead of null value * Apply review suggestions --- setup/compiler.class.inc.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index adb59303e..a4f9b5d72 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -1165,6 +1165,7 @@ EOF */ protected function QuoteForPHP($sStr, $bSimpleQuotes = false) { + $sStr = $sStr ?? ''; if ($bSimpleQuotes) { $sEscaped = str_replace(array('\\', "'"), array('\\\\', "\\'"), $sStr); @@ -3229,10 +3230,11 @@ EOF; $aEntriesPHP = array(); $oEntries = $oDictionaryNode->GetUniqueElement('entries'); + /** @var MFElement $oEntry */ foreach ($oEntries->getElementsByTagName('entry') as $oEntry) { $sStringCode = $oEntry->getAttribute('id'); - $sValue = $oEntry->GetText(); + $sValue = $oEntry->GetText(''); $aEntriesPHP[] = "\t'$sStringCode' => ".self::QuoteForPHP(self::FilterDictString($sValue), true).","; } $sEntriesPHP = implode("\n", $aEntriesPHP); @@ -3267,7 +3269,7 @@ EOF; file_put_contents($sLanguagesFile, $sLanguagesFileContent); } - protected static function FilterDictString($s) + protected static function FilterDictString(string $s): string { if (strpos($s, '~') !== false) {