Skip to content

Commit fedca02

Browse files
committed
Optimized pdo_pgsql connection test
1 parent 4bb7505 commit fedca02

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ext/pdo_pgsql/tests/gh12423.phpt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
--TEST--
22
GitHub #12424 (Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments.)
3+
--EXTENSIONS--
4+
pdo
5+
pdo_pgsql
36
--SKIPIF--
47
<?php
5-
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
68
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
79
require __DIR__ . '/config.inc';
810
PDOTest::skip();
@@ -15,14 +17,16 @@ $dsnWithCredentials = $config['ENV']['PDOTEST_DSN'];
1517
$user = $config['ENV']['PDOTEST_USER'] ?? null;
1618
$password = $config['ENV']['PDOTEST_PASS'] ?? null;
1719
if (!$user) {
18-
preg_match('/user=(.*?) /', $dsnWithCredentials, $match);
19-
$user = $match[1] ?? '';
20+
preg_match('/user=([^ ]*?) /', $dsnWithCredentials, $match);
21+
$user = $match[1] ?? null;
2022
}
2123
if (!$password) {
22-
preg_match('/password=(.*?) /', $dsnWithCredentials, $match);
23-
$password = $match[1] ?? '';
24+
preg_match('/password=([^ ]*?)/', $dsnWithCredentials, $match);
25+
$password = $match[1] ?? null;
2426
}
25-
$dsn = str_replace(" user={$user} password={$password}", '', $dsnWithCredentials);
27+
$dsn = str_replace("user={$user}", '', $dsnWithCredentials);
28+
$dsn = str_replace("password={$password}", '', $dsn);
29+
$dsn = rtrim($dsn);
2630

2731
echo "dsn without credentials / correct user / correct password\n";
2832
try {

0 commit comments

Comments
 (0)