Просмотр исходного кода

Fix gelf formatter keys to strip invalid characters, fixes #1927

Jordi Boggiano 1 год назад
Родитель
Сommit
595847346a

+ 1 - 0
src/Monolog/DateTimeImmutable.php

@@ -13,6 +13,7 @@ namespace Monolog;
 
 class_alias(JsonSerializableDateTimeImmutable::class, 'Monolog\DateTimeImmutable');
 
+// @phpstan-ignore-next-line
 if (false) {
     /**
      * @deprecated Use \Monolog\JsonSerializableDateTimeImmutable instead.

+ 2 - 0
src/Monolog/Formatter/GelfMessageFormatter.php

@@ -115,6 +115,7 @@ class GelfMessageFormatter extends NormalizerFormatter
         }
 
         foreach ($extra as $key => $val) {
+            $key = (string) preg_replace('#[^\w\.\-]#', '-', $key);
             $val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
             $len = \strlen($this->extraPrefix . $key . $val);
             if ($len > $this->maxLength) {
@@ -126,6 +127,7 @@ class GelfMessageFormatter extends NormalizerFormatter
         }
 
         foreach ($context as $key => $val) {
+            $key = (string) preg_replace('#[^\w\.\-]#', '-', $key);
             $val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
             $len = \strlen($this->contextPrefix . $key . $val);
             if ($len > $this->maxLength) {