Преглед на файлове

Fix gelf message formatter failing to handle context/extra numeric keys, fixes #1932

Jordi Boggiano преди 10 месеца
родител
ревизия
467e764fb6
променени са 2 файла, в които са добавени 3 реда и са изтрити 3 реда
  1. 2 2
      src/Monolog/Formatter/GelfMessageFormatter.php
  2. 1 1
      tests/Monolog/Formatter/GelfMessageFormatterTest.php

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

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

+ 1 - 1
tests/Monolog/Formatter/GelfMessageFormatterTest.php

@@ -67,7 +67,7 @@ class GelfMessageFormatterTest extends MonologTestCase
             channel: 'meh',
             context: ['from' => 'logger'],
             datetime: new \DateTimeImmutable("@0"),
-            extra: ['file' => 'test', 'line' => 14],
+            extra: ['file' => 'test', 'line' => 14, 0 => 'foo'],
         );
 
         $message = $formatter->format($record);