Browse Source

Fix binary log conversation.

mscherer 6 years ago
parent
commit
8be4f212b5
2 changed files with 20 additions and 2 deletions
  1. 2 2
      src/Database/Log/LoggedQuery.php
  2. 18 0
      tests/TestCase/Database/Log/LoggedQueryTest.php

+ 2 - 2
src/Database/Log/LoggedQuery.php

@@ -78,8 +78,8 @@ class LoggedQuery implements JsonSerializable
             }
 
             if (is_string($p)) {
-                // Likely binary data.
-                if (!ctype_print($p)) {
+                // Likely binary UUID.
+                if (strlen($p) === 16 && !ctype_print($p)) {
                     $p = bin2hex($p);
                 }
 

+ 18 - 0
tests/TestCase/Database/Log/LoggedQueryTest.php

@@ -128,6 +128,24 @@ class LoggedQueryTest extends TestCase
         $this->assertEquals($expected, (string)$query);
     }
 
+    /**
+     * Tests that unknown possible binary data is not replaced to hex.
+     *
+     * @return void
+     */
+    public function testBinaryInterpolationIgnored()
+    {
+        $query = new LoggedQuery();
+        $query->query = 'SELECT a FROM b where a = :p1';
+        $query->params = ['p1' => "a\tz"];
+
+        $expected = "duration=0 rows=0 SELECT a FROM b where a = 'a\tz'";
+        $this->assertEquals($expected, (string)$query);
+    }
+
+    /**
+     * @return void
+     */
     public function testJsonSerialize()
     {
         $query = new LoggedQuery();