2
0
Эх сурвалжийг харах

Avoid sending unicode chars in headers for Wildfire/FirePHPHandler/ChromePHPHandler, fixes #1521

Jordi Boggiano 5 жил өмнө
parent
commit
863670fa94

+ 11 - 0
src/Monolog/Formatter/WildfireFormatter.php

@@ -36,6 +36,17 @@ class WildfireFormatter extends NormalizerFormatter
         Logger::EMERGENCY => 'ERROR',
     ];
 
+    /**
+     * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format
+     */
+    public function __construct(?string $dateFormat = null)
+    {
+        parent::__construct($dateFormat);
+
+        // http headers do not like non-ISO-8559-1 characters
+        $this->removeJsonEncodeOption(JSON_UNESCAPED_UNICODE);
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 1
src/Monolog/Handler/ChromePHPHandler.php

@@ -145,7 +145,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
             self::$json['request_uri'] = $_SERVER['REQUEST_URI'] ?? '';
         }
 
-        $json = Utils::jsonEncode(self::$json, null, true);
+        $json = Utils::jsonEncode(self::$json, Utils::DEFAULT_JSON_FLAGS & ~JSON_UNESCAPED_UNICODE, true);
         $data = base64_encode(utf8_encode($json));
         if (strlen($data) > 3 * 1024) {
             self::$overflowed = true;

+ 1 - 1
src/Monolog/Utils.php

@@ -63,7 +63,7 @@ final class Utils
      * Return the JSON representation of a value
      *
      * @param  mixed             $data
-     * @param  int               $encodeFlags  flags to pass to json encode, defaults to JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
+     * @param  int               $encodeFlags  flags to pass to json encode, defaults to DEFAULT_JSON_FLAGS
      * @param  bool              $ignoreErrors whether to ignore encoding errors or to throw on error, when ignored and the encoding fails, "null" is returned which is valid json for null
      * @throws \RuntimeException if encoding fails and errors are not ignored
      * @return string            when errors are ignored and the encoding fails, "null" is returned which is valid json for null