Harden timeline quick extraction
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user