mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 12:47:39 +02:00
Fix json formatter handling of incomplete classes, fixes #1834
This commit is contained in:
@@ -192,6 +192,10 @@ class JsonFormatter extends NormalizerFormatter
|
||||
return $data;
|
||||
}
|
||||
|
||||
if (\get_class($data) === '__PHP_Incomplete_Class') {
|
||||
return new \ArrayObject($data);
|
||||
}
|
||||
|
||||
if (method_exists($data, '__toString')) {
|
||||
return $data->__toString();
|
||||
}
|
||||
|
@@ -297,6 +297,18 @@ class JsonFormatterTest extends TestCase
|
||||
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
|
||||
}
|
||||
|
||||
public function testCanNormalizeIncompleteObject(): void
|
||||
{
|
||||
$serialized = "O:17:\"Monolog\TestClass\":1:{s:23:\"\x00Monolog\TestClass\x00name\";s:4:\"test\";}";
|
||||
$object = unserialize($serialized);
|
||||
|
||||
$formatter = new JsonFormatter();
|
||||
$record = ['context' => ['object' => $object]];
|
||||
$result = $formatter->format($record);
|
||||
|
||||
self::assertSame('{"context":{"object":{"__PHP_Incomplete_Class_Name":"Monolog\\\\TestClass"}}}'."\n", $result);
|
||||
}
|
||||
|
||||
public function testEmptyContextAndExtraFieldsCanBeIgnored()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true, true);
|
||||
|
Reference in New Issue
Block a user