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

fix(dsn): preserve leading slash in parsed DSN path

phpdevcommunity 3 долоо хоног өмнө
parent
commit
1dbdb0e9f5

+ 5 - 4
src/Parser/DSNParser.php

@@ -24,10 +24,8 @@ final class DSNParser
             if ($path === '' || $path === 'memory' || $path === ':memory:') {
                 $memory = true;
                 $path = null;
-            } else {
-                if (str_starts_with($rest, '///')) {
+            } elseif (str_starts_with($rest, '///')) {
                     $path = '/' . $path;
-                }
             }
 
             return [
@@ -54,7 +52,10 @@ final class DSNParser
         $port = isset($params['port']) ? (int) $params['port'] : null;
         $user = $params['user'] ?? null;
         $password = $params['pass'] ?? null;
-        $path = isset($params['path']) ? ltrim($params['path'], '/') : null;
+        $path = $params['path'] ?? null;
+        if ($path !== null && $path[0] === '/') {
+            $path = substr($path, 1);
+        }
         $isMemory = ($path === 'memory' || $path === ':memory:');
 
         return [

+ 17 - 0
tests/Common/DSNParserTest.php

@@ -58,5 +58,22 @@ class DSNParserTest extends TestCase
             ]],
             DSNParser::parse('sqlite:///app.db?mode=ro&cache=shared')
         );
+
+        $this->assertEquals(
+            [
+                'driver' => 'sql',
+                'host' => '127.0.0.1',
+                'port' => 5002,
+                'user' => 'root',
+                'password' => '',
+                'path' => '/dbs/mydb',
+                'memory' => false,
+                'options' =>
+                    [
+                        'charset_utf8' => '1',
+                    ],
+            ],
+            DSNParser::parse('sql://root:@127.0.0.1:5002//dbs/mydb?charset_utf8=1')
+        );
     }
 }

+ 2 - 2
tests/DatabaseShowTablesCommandTest.php

@@ -78,7 +78,7 @@ class DatabaseShowTablesCommandTest extends TestCase
         }));
 
         $this->assertEquals(0, $code);
-        $this->assertEquals(16, count($out));
+        $this->assertEquals(18, count($out));
 
         $out = [];
         $code = $runner->run(new CommandParser(['', 'paper:show:tables', 'post', '--columns']), new Output(function ($message) use(&$out) {
@@ -86,7 +86,7 @@ class DatabaseShowTablesCommandTest extends TestCase
         }));
 
         $this->assertEquals(0, $code);
-        $this->assertEquals(62, count($out));
+        $this->assertEquals(132, count($out));
 
 
         $platform->dropDatabase();