fix ipv6 database host

This commit is contained in:
Robin Appelman 2026-03-04 15:03:57 +01:00
commit 70543db580
3 changed files with 54 additions and 9 deletions

View file

@ -721,3 +721,35 @@ fn test_parse_postgres_escaped_credentials() {
PgConnectOptions::from_str(&config.database.url()).unwrap(),
);
}
#[test]
fn test_parse_ipv6_db() {
let config = config_from_file("tests/configs/ipv6_db.php");
assert_debug_equal(
&Database::MySql {
database: "nextcloud".to_string(),
username: "nextcloud".to_string(),
password: "secret".to_string(),
connect: DbConnect::Tcp {
host: "[::1]".to_string(),
port: 123,
},
ssl_options: SslOptions::Default,
},
&config.database,
);
assert_eq!(
config.database.url(),
"mysql://nextcloud:secret@[::1]:123/nextcloud"
);
assert_debug_equal(
MySqlConnectOptions::new()
.host("[::1]")
.username("nextcloud")
.password("secret")
.port(123)
.database("nextcloud"),
MySqlConnectOptions::from_str(&config.database.url()).unwrap(),
);
}

15
tests/configs/ipv6_db.php Normal file
View file

@ -0,0 +1,15 @@
<?php
$CONFIG = [
'overwrite.cli.url' => 'https://cloud.example.com',
'dbtype' => 'mysql',
'dbname' => 'nextcloud',
'dbhost' => '[::1]:123',
'dbport' => '',
'dbtableprefix' => 'oc_',
'dbuser' => 'nextcloud',
'dbpassword' => 'secret',
'redis' => [
'host' => 'localhost'
]
];