From 58a7b12f03bfe201cc7856065eed5093dc661839 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 3 Nov 2026 13:41:29 +0400 Subject: [PATCH] fix: send arrays and objects as JSON without escaped slashes and unicode RoadRunner prints the attribute string as it is, so `\/` and `\uXXXX` ended up in the log line instead of `/` and the actual characters. Assisted-By: Claude Opus 5.5 --- src/Logger.php | 2 +- tests/LoggerTest.php | 1 + tests/RpcMock.php | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Logger.php b/src/Logger.php index db8d582..b9d4a2f 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -145,6 +145,6 @@ private function prepareValue(mixed $value): string return (string) $value; } - return \json_encode($value, JSON_THROW_ON_ERROR); + return \json_encode($value, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); } } diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php index 256524c..b0951fe 100644 --- a/tests/LoggerTest.php +++ b/tests/LoggerTest.php @@ -38,6 +38,7 @@ public function __toString(): string yield 'null' => [null, 'null']; yield 'list' => [[1, 'two'], '[1,"two"]']; yield 'map' => [['a' => ['b' => 1]], '{"a":{"b":1}}']; + yield 'slashes and unicode' => [['path' => '/var/log', 'name' => 'Дорога'], '{"path":"/var/log","name":"Дорога"}']; } public function testErrorCall(): void diff --git a/tests/RpcMock.php b/tests/RpcMock.php index d6c6f01..86fdee1 100644 --- a/tests/RpcMock.php +++ b/tests/RpcMock.php @@ -66,7 +66,13 @@ public function assertCalledWithContext(LogLevel $level, array $message, int $ti ->with( $level->name . 'WithContext', \Mockery::on(function (LogEntry $logEntry) use ($message): bool { - Assert::same($logEntry->serializeToJsonString(), \json_encode($message)); + // Not via serializeToJsonString(): its escaping of `/` differs between protobuf builds + $attributes = []; + foreach ($logEntry->getLogAttrs() as $attr) { + $attributes[] = ['key' => $attr->getKey(), 'value' => $attr->getValue()]; + } + + Assert::same(['message' => $logEntry->getMessage(), 'logAttrs' => $attributes], $message); return true; }), )