Jordi Boggiano 6 лет назад
Родитель
Сommit
4e19f3c585

+ 17 - 2
CHANGELOG.md

@@ -1,5 +1,11 @@
-### 2.0.1 (xx)
-
+### 2.0.1 (2019-11-13)
+
+  * Fixed normalization of Traversables to avoid traversing them as not all of them are rewindable
+  * Fixed setFormatter/getFormatter to forward to the nested handler in FilterHandler, FingersCrossedHandler, BufferHandler and SamplingHandler
+  * Fixed BrowserConsoleHandler formatting when using multiple styles
+  * Fixed normalization of exception codes to be always integers even for PDOException which have them as numeric strings
+  * Fixed normalization of SoapFault objects containing non-strings as "detail"
+  * Fixed json encoding across all handlers to always attempt recovery of non-UTF-8 strings instead of failing the whole encoding
   * Fixed ChromePHPHandler to avoid sending more data than latest Chrome versions allow in headers (4KB down from 256KB).
   * Fixed type error in BrowserConsoleHandler when the context array of log records was not associative.
 
@@ -52,6 +58,15 @@
   * Added support for the PHP 7.x `mongodb` extension in the MongoDBHandler
   * Fixed many minor issues in various handlers, and probably added a few regressions too
 
+### 1.25.2 (2019-11-13)
+
+  * Fixed normalization of Traversables to avoid traversing them as not all of them are rewindable
+  * Fixed setFormatter/getFormatter to forward to the nested handler in FilterHandler, FingersCrossedHandler, BufferHandler and SamplingHandler
+  * Fixed BrowserConsoleHandler formatting when using multiple styles
+  * Fixed normalization of exception codes to be always integers even for PDOException which have them as numeric strings
+  * Fixed normalization of SoapFault objects containing non-strings as "detail"
+  * Fixed json encoding across all handlers to always attempt recovery of non-UTF-8 strings instead of failing the whole encoding
+
 ### 1.25.1 (2019-09-06)
 
   * Fixed forward-compatible interfaces to be compatible with Monolog 1.x too.

+ 18 - 0
src/Monolog/Handler/BufferHandler.php

@@ -130,4 +130,22 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
             $this->handler->reset();
         }
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function setFormatter(FormatterInterface $formatter)
+    {
+        $this->handler->setFormatter($formatter);
+
+        return $this;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getFormatter()
+    {
+        return $this->handler->getFormatter();
+    }
 }

+ 2 - 2
src/Monolog/Handler/Slack/SlackRecord.php

@@ -217,8 +217,8 @@ class SlackRecord
         $hasNonNumericKeys = !count(array_filter(array_keys($normalized), 'is_numeric'));
 
         return $hasSecondDimension || $hasNonNumericKeys
-            ? Utils::jsonEncode($normalized, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)
-            : Utils::jsonEncode($normalized, JSON_UNESCAPED_UNICODE);
+            ? Utils::jsonEncode($normalized, JSON_PRETTY_PRINT|Utils::DEFAULT_JSON_FLAGS)
+            : Utils::jsonEncode($normalized, Utils::DEFAULT_JSON_FLAGS);
     }
 
     /**

+ 8 - 4
src/Monolog/Utils.php

@@ -49,13 +49,17 @@ final class Utils
             $encodeFlags = self::DEFAULT_JSON_FLAGS;
         }
 
-        $json = json_encode($data, $encodeFlags);
-
-        if (false === $json) {
-            if ($ignoreErrors) {
+        if ($ignoreErrors) {
+            $json = @json_encode($data, $encodeFlags);
+            if (false === $json) {
                 return 'null';
             }
 
+            return $json;
+        }
+
+        $json = json_encode($data, $encodeFlags);
+        if (false === $json) {
             $json = self::handleJsonError(json_last_error(), $data);
         }
 

+ 10 - 2
tests/Monolog/Formatter/NormalizerFormatterTest.php

@@ -188,7 +188,11 @@ class NormalizerFormatterTest extends TestCase
 
         restore_error_handler();
 
-        $this->assertEquals('null', $res);
+        if (PHP_VERSION_ID < 50500) {
+            $this->assertEquals('[{"bar":{"foo":null}},{"foo":{"bar":null}}]', $res);
+        } else {
+            $this->assertEquals('null', $res);
+        }
     }
 
     public function testCanNormalizeReferences()
@@ -223,7 +227,11 @@ class NormalizerFormatterTest extends TestCase
 
         restore_error_handler();
 
-        $this->assertEquals('null', $res);
+        if (PHP_VERSION_ID < 50500) {
+            $this->assertEquals('[null]', $res);
+        } else {
+            $this->assertEquals('null', $res);
+        }
     }
 
     public function testNormalizeHandleLargeArraysWithExactly1000Items()

+ 5 - 14
tests/Monolog/Handler/Slack/SlackRecordTest.php

@@ -19,13 +19,6 @@ use Monolog\Test\TestCase;
  */
 class SlackRecordTest extends TestCase
 {
-    private $jsonPrettyPrintFlag;
-
-    protected function setUp(): void
-    {
-        $this->jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
-    }
-
     public function dataGetAttachmentColor()
     {
         return array(
@@ -78,16 +71,14 @@ class SlackRecordTest extends TestCase
      */
     public function dataStringify()
     {
-        $jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
-
         $multipleDimensions = array(array(1, 2));
         $numericKeys = array('library' => 'monolog');
         $singleDimension = array(1, 'Hello', 'Jordi');
 
         return array(
             array(array(), '[]'),
-            array($multipleDimensions, json_encode($multipleDimensions, $jsonPrettyPrintFlag)),
-            array($numericKeys, json_encode($numericKeys, $jsonPrettyPrintFlag)),
+            array($multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)),
+            array($numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)),
             array($singleDimension, json_encode($singleDimension)),
         );
     }
@@ -271,12 +262,12 @@ class SlackRecordTest extends TestCase
             array(
                 array(
                     'title' => 'Extra',
-                    'value' => sprintf('```%s```', json_encode($extra, $this->jsonPrettyPrintFlag)),
+                    'value' => sprintf('```%s```', json_encode($extra, JSON_PRETTY_PRINT)),
                     'short' => false,
                 ),
                 array(
                     'title' => 'Context',
-                    'value' => sprintf('```%s```', json_encode($context, $this->jsonPrettyPrintFlag)),
+                    'value' => sprintf('```%s```', json_encode($context, JSON_PRETTY_PRINT)),
                     'short' => false,
                 ),
             ),
@@ -381,7 +372,7 @@ class SlackRecordTest extends TestCase
         $expected = array(
             array(
                 'title' => 'Info',
-                'value' => sprintf('```%s```', json_encode(array('author' => 'Jordi'), $this->jsonPrettyPrintFlag)),
+                'value' => sprintf('```%s```', json_encode(array('author' => 'Jordi'), JSON_PRETTY_PRINT)),
                 'short' => false,
             ),
             array(