From 02388a39423ef403f677e810b1f20504693e7714 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Apr 2018 14:47:04 +0200 Subject: [PATCH] Allow IPv6 database hosts Signed-off-by: Joas Schilling --- lib/private/DB/ConnectionFactory.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index fcb0117a0db..bfa2cf5b7b4 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -193,13 +193,14 @@ class ConnectionFactory { $connectionParams['path'] = $dataDir . '/' . $name . '.db'; } else { $host = $this->config->getValue('dbhost', ''); - if (strpos($host, ':')) { - // Host variable may carry a port or socket. - list($host, $portOrSocket) = explode(':', $host, 2); - if (ctype_digit($portOrSocket)) { - $connectionParams['port'] = $portOrSocket; + $matches = []; + if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) { + // Host variable carries a port or socket. + $host = $matches[1]; + if (is_numeric($matches[2])) { + $connectionParams['port'] = (int) $matches[2]; } else { - $connectionParams['unix_socket'] = $portOrSocket; + $connectionParams['unix_socket'] = $matches[2]; } } $connectionParams['host'] = $host;