Skip to content

Commit e2539d8

Browse files
CopilotRello
andcommitted
Improve error handling and regex pattern in enterprise version endpoint
Co-authored-by: Rello <[email protected]>
1 parent b89bf4a commit e2539d8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

index.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424

2525
// Extract enterpriseVersion from the config file by parsing it
2626
$configContent = file_get_contents(__DIR__ . '/config/config.php');
27-
preg_match('/\$enterpriseVersion\s*=\s*[\'"]([^\'"]+)[\'"]/', $configContent, $matches);
27+
if ($configContent === false) {
28+
http_response_code(500);
29+
echo json_encode(['error' => 'Failed to read configuration file'], JSON_THROW_ON_ERROR);
30+
exit();
31+
}
32+
33+
preg_match('/\$enterpriseVersion\s*=\s*[\'"]([^\'"\r\n]+)[\'"]/', $configContent, $matches);
2834
$enterpriseVersion = isset($matches[1]) ? $matches[1] : null;
2935

30-
echo json_encode(['enterpriseVersion' => $enterpriseVersion]);
36+
echo json_encode(['enterpriseVersion' => $enterpriseVersion], JSON_THROW_ON_ERROR);
3137
exit();
3238
}
3339

0 commit comments

Comments
 (0)