Harden timeline quick extraction

This commit is contained in:
2026-05-25 11:14:21 +02:00
parent 983c423740
commit 3ad8f4843c
3 changed files with 185 additions and 8 deletions
+9 -2
View File
@@ -149,13 +149,20 @@ final class DbnAzureOpenAiGateway
public function decodeJsonObject(string $content): ?array
{
$content = trim($content);
$content = (string)preg_replace('/^```(?:json)?\s*\n?/i', '', $content);
$content = (string)preg_replace('/\n?```\s*$/', '', $content);
$content = trim($content);
$decoded = json_decode($content, true);
if (is_array($decoded)) {
return $decoded;
}
if (preg_match('/\{(?:[^{}]|(?R))*\}/s', $content, $match)) {
$decoded = json_decode($match[0], true);
$start = strpos($content, '{');
$end = strrpos($content, '}');
if ($start !== false && $end !== false && $end > $start) {
$candidate = substr($content, $start, $end - $start + 1);
$decoded = json_decode($candidate, true);
if (is_array($decoded)) {
return $decoded;
}