Skip to content

Commit 9523f6c

Browse files
committed
Use the doctrine dsn parser to decode the database url
1 parent 4e15076 commit 9523f6c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
## WIP
66

77
- Fixed an error that occurred when parsing table name patterns ([#190](https://github.com/Smile-SA/gdpr-dump/pull/190))
8+
- Fixed an error that occurred when the database url contains special characters ([#196](https://github.com/Smile-SA/gdpr-dump/pull/196))
89

910
## [5.0.5] - 2025-04-05
1011
[5.0.5]: https://github.com/Smile-SA/gdpr-dump/compare/5.0.4...5.0.5

src/Config/Compiler/Processor/DatabaseUrlProcessor.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Smile\GdprDump\Config\Compiler\Processor;
66

7+
use Doctrine\DBAL\Exception\MalformedDsnException;
8+
use Doctrine\DBAL\Tools\DsnParser;
79
use Smile\GdprDump\Config\Compiler\CompileException;
810
use Smile\GdprDump\Config\ConfigInterface;
911
use Smile\GdprDump\Database\DatabaseInterface;
@@ -38,23 +40,24 @@ private function processDatabaseNode(array $database): array
3840

3941
// Validate url
4042
if (!filter_var($url, FILTER_VALIDATE_URL)) {
41-
throw new CompileException(sprintf('The value "%s" is not a valid URL.', $url));
43+
throw new CompileException(sprintf('The value "%s" is not a valid database URL.', $url));
4244
}
4345

4446
// Parse url
45-
$parsedUrl = parse_url($url);
46-
if ($parsedUrl === false) {
47-
throw new CompileException(sprintf('Failed to parse the url "%s".', $url));
47+
try {
48+
$parsedUrl = (new DsnParser())->parse($url);
49+
} catch (MalformedDsnException $e) {
50+
throw new CompileException(sprintf('Failed to parse the database url "%s".', $url), $e);
4851
}
4952

5053
// Update database params from parsed url
5154
$map = [
52-
'scheme' => 'driver',
53-
'path' => 'name',
55+
'driver' => 'driver',
56+
'dbname' => 'name',
5457
'host' => 'host',
5558
'port' => 'port',
5659
'user' => 'user',
57-
'pass' => 'password',
60+
'password' => 'password',
5861
];
5962

6063
foreach ($map as $urlPart => $dbParam) {
@@ -65,7 +68,6 @@ private function processDatabaseNode(array $database): array
6568

6669
$value = (string) $parsedUrl[$urlPart];
6770
$database[$dbParam] = match ($dbParam) {
68-
'name' => ltrim($value, '/'),
6971
'driver' => $this->getDriverByScheme($value),
7072
default => $value
7173
};

0 commit comments

Comments
 (0)