Skip to content

Commit 83b59e7

Browse files
committed
wip
1 parent 03d6c6d commit 83b59e7

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

src/Illuminate/Database/Console/DbCommand.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\ConfigurationUrlParser;
7+
use Illuminate\Support\Uri;
78
use PDO;
89
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -289,34 +290,17 @@ protected function buildDatabaseUrl(array $connection)
289290
return $connection['database'];
290291
}
291292

292-
$url = "{$driver}://";
293-
294-
if (! empty($connection['username'])) {
295-
$url .= urlencode($connection['username']);
296-
297-
if (! empty($connection['password'])) {
298-
$url .= ':'.urlencode($connection['password']);
299-
}
300-
301-
$url .= '@';
302-
}
303-
304-
$url .= $connection['host'];
305-
306-
if (! empty($connection['port'])) {
307-
$url .= ":{$connection['port']}";
308-
}
309-
310-
if (! empty($connection['database'])) {
311-
$url .= '/'.urlencode($connection['database']);
312-
}
313-
314-
$queryParams = $this->getQueryParameters($connection);
315-
if (! empty($queryParams)) {
316-
$url .= '?'.http_build_query($queryParams);
317-
}
318-
319-
return $url;
293+
return (new Uri)
294+
->withScheme($driver)
295+
->withHost($connection['host'])
296+
->withUser(
297+
$connection['username'] ?? null,
298+
! empty($connection['password']) ? $connection['password'] : null,
299+
)
300+
->when(! empty($connection['port']), fn (Uri $uri) => $uri->withPort((int) $connection['port']))
301+
->when(! empty($connection['database']), fn (Uri $uri) => $uri->withPath($connection['database']))
302+
->when(! empty($this->getQueryParameters($connection)), fn (Uri $uri) => $uri->withQuery($this->getQueryParameters($connection)))
303+
->value();
320304
}
321305

322306
/**

tests/Database/DbCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testBuildDatabaseUrlForSqlServer()
8181

8282
$url = $command->buildDatabaseUrl($connection);
8383

84-
$this->assertSame('sqlserver://sa:Password123%21@localhost:1433/master', $url);
84+
$this->assertSame('sqlserver://sa:Password123!@localhost:1433/master', $url);
8585
}
8686

8787
public function testBuildDatabaseUrlWithSpecialCharactersInPassword()
@@ -99,7 +99,7 @@ public function testBuildDatabaseUrlWithSpecialCharactersInPassword()
9999

100100
$url = $command->buildDatabaseUrl($connection);
101101

102-
$this->assertSame('mysql://root:p%40ss%3Aword%21%23%24@localhost:3306/forge', $url);
102+
$this->assertSame('mysql://root:p%40ss:word!%23$@localhost:3306/forge', $url);
103103
}
104104

105105
public function testBuildDatabaseUrlWithoutPassword()

0 commit comments

Comments
 (0)