Skip to content

Commit 258bafe

Browse files
committed
Fix acceptance of escaped spaces in connection strings
1 parent e7ab2f4 commit 258bafe

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/SqlConfig.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class SqlConfig
1313
];
1414

1515
private const KEY_VALUE_PAIR_REGEXP = <<<'REGEXP'
16-
[\G\s*(\w+)=((['"])(?:\\(?:\\|\3)|(?!\3).)*+\3|[^ '";]\S*?)(?:\s+|;|$)]
16+
[\G\s*(\w+)=((['"])(?:\\(?:\\|\3)|(?!\3).)*+\3|[^ '";](?:\\(?:\\| )|(?!\s+|;| ).)*+)(?:\s+|;|$)]
1717
REGEXP;
1818

1919
private string $host;
@@ -62,6 +62,8 @@ protected static function parseConnectionString(string $connectionString, array
6262
if ($value === '') {
6363
throw new \ValueError("Empty connection string value for key '{$key}'");
6464
}
65+
} else {
66+
$value = \str_replace('\\ ', ' ', $value);
6567
}
6668

6769
\assert($key !== null && $key !== '');

test/SqlConfigTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ public function testQuoteInQuotedValue(): void
6565
self::assertSame('test', $config->getDatabase());
6666
}
6767

68+
public function testEscapedSpace(): void
69+
{
70+
$config = $this->createConfigFromString(
71+
<<<'CS'
72+
host=localhost user=Test\ User database=Test\ Name
73+
CS
74+
);
75+
76+
self::assertSame('localhost', $config->getHost());
77+
self::assertSame('Test User', $config->getUser());
78+
self::assertSame('Test Name', $config->getDatabase());
79+
}
80+
6881
public function provideInvalidConnectionStrings(): array
6982
{
7083
return [

0 commit comments

Comments
 (0)