From 23e777d50dba2edf12eb6b1a17c60cce7e9f5928 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Thu, 28 May 2026 17:01:12 -0500 Subject: [PATCH] fix: prevent preg_replace null from truncating files to 0 bytes preg_replace returns null on error. Without a null check, the result was written to files as empty content, destroying all XML manifests during the release pipeline. Added null guards to all file_put_contents calls after preg_replace in version_set_platform.php, version_check.php, and version_bump.php. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- cli/version_bump.php | 10 +++++++--- cli/version_check.php | 12 ++++++++---- cli/version_set_platform.php | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cli/version_bump.php b/cli/version_bump.php index b6a24db..ece23de 100644 --- a/cli/version_bump.php +++ b/cli/version_bump.php @@ -125,7 +125,9 @@ if (file_exists($mokoManifest) && !empty($mokoContent)) { $mokoContent, 1 ); - file_put_contents($mokoManifest, $updated); + if ($updated !== null) { + file_put_contents($mokoManifest, $updated); + } } // -- Update README.md -- @@ -136,7 +138,9 @@ if (file_exists($readme) && !empty($readmeContent)) { $readmeContent, 1 ); - file_put_contents($readme, $updated); + if ($updated !== null) { + file_put_contents($readme, $updated); + } } // -- Cascade to ALL Joomla extension XML manifests -- @@ -160,7 +164,7 @@ foreach ($xmlPatterns as $pattern) { "{$newFull}", $content ); - if ($newContent !== $content) { + if ($newContent !== null && $newContent !== $content) { file_put_contents($xmlFile, $newContent); $updatedFiles[] = substr($xmlFile, strlen($root) + 1); } diff --git a/cli/version_check.php b/cli/version_check.php index e5e2379..ff4d538 100644 --- a/cli/version_check.php +++ b/cli/version_check.php @@ -99,13 +99,15 @@ if (count($uniqueVersions) === 1) { // Fix README.md if (isset($versions['README.md']) && $versions['README.md'] !== $highestVersion) { $content = file_get_contents($readme); - $content = preg_replace( + $updated = preg_replace( '/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}/m', '${1}' . $highestVersion, $content, 1 ); - file_put_contents($readme, $content); + if ($updated !== null) { + file_put_contents($readme, $updated); + } echo " Fixed: README.md -> {$highestVersion}\n"; } @@ -118,12 +120,14 @@ if (count($uniqueVersions) === 1) { if (!file_exists($file)) continue; $content = file_get_contents($file); - $content = preg_replace( + $updated = preg_replace( '|[^<]*|', "{$highestVersion}", $content ); - file_put_contents($file, $content); + if ($updated !== null) { + file_put_contents($file, $updated); + } echo " Fixed: {$source} -> {$highestVersion}\n"; } diff --git a/cli/version_set_platform.php b/cli/version_set_platform.php index d661ad6..c5d0297 100644 --- a/cli/version_set_platform.php +++ b/cli/version_set_platform.php @@ -152,7 +152,7 @@ if (in_array($platform, ['waas-component', 'joomla'], true)) { "{$version}", $content ); - if ($updated !== $content) { + if ($updated !== null && $updated !== $content) { file_put_contents($file, $updated); $relPath = str_replace($root . '/', '', $file); echo "Joomla: {$relPath} → {$version}\n";